Skip to content

All your computers and your phone/iPhone, working as one desk. Screens, apps, files, clipboard, calls, texts, notifications, mouse and keyboard, shared between Mac, Windows, Linux , Android, Web and ios / ipados . Free and open source. No account, no cloud, and no shared network needed.

1.7 KB
Raw Blame
// TwinDesk — Copyright (C) 2026 inukaasith. GPL-3.0, see LICENSE.
using System;
using MacShare;

class LaneMoveRingTest
{
    static void Check(bool actual, bool expected, string name)
    {
        if (actual != expected) throw new Exception(name);
    }

    static void Near(double actual, double expected, string name)
    {
        if (Math.Abs(actual - expected) > 1e-9) throw new Exception(name + " got " + actual);
    }

    static void Main()
    {
        LaneMoveRing ring = new LaneMoveRing();
        double dx, dy;

        ring.Enqueue(1, 2);
        ring.Enqueue(3, 4);
        ring.Enqueue(-0.5, 1);
        Check(ring.TryDrainCoalesced(out dx, out dy), true, "coalesce");
        Near(dx, 3.5, "coalesce dx");
        Near(dy, 7, "coalesce dy");
        Check(ring.TryDrainCoalesced(out dx, out dy), false, "empty after drain");
        if (ring.Queued != 0) throw new Exception("queue empty");

        ring.Reset();
        for (int i = 0; i < LaneMoveRing.Capacity + 16; i++) ring.Enqueue(1, -1);
        Check(ring.TryDrainCoalesced(out dx, out dy), true, "overflow drain");
        Near(dx, LaneMoveRing.Capacity + 16, "overflow dx");
        Near(dy, -(LaneMoveRing.Capacity + 16), "overflow dy");
        if (ring.Queued != 0) throw new Exception("overflow emptied");

        ring.Reset();
        ring.Enqueue(1e200, 0);
        ring.Enqueue(1e200, 0);
        Check(ring.TryDrainCoalesced(out dx, out dy), true, "large delta");
        Near(dx, 2e200, "large dx");

        ring.Reset();
        ring.Enqueue(0, 0);
        ring.Enqueue(0, 0);
        Check(ring.TryDrainCoalesced(out dx, out dy), false, "zero-only");

        Console.WriteLine("LaneMoveRing: passed");
    }
}