Beispiel #1
0
        public void One_LevelIndirect_To_COM_Equals_2()
        {
            var sut = new OrbitMap();

            sut.AddOrbit("COM", "AAA");
            sut.AddOrbit("AAA", "BBB");

            Assert.Equal(2, sut.Checksum("BBB"));
        }
Beispiel #2
0
        public void Order_Of_Adding_Orbits_Doesnt_Affect_Checksum()
        {
            var sut = new OrbitMap();

            sut.AddOrbit("BBB", "CCC");
            sut.AddOrbit("AAA", "BBB");
            sut.AddOrbit("COM", "AAA");

            Assert.Equal(3, sut.Checksum("CCC"));
        }
Beispiel #3
0
        public void Two_Level_Indirect_To_COM_Equals_3()
        {
            var sut = new OrbitMap();

            sut.AddOrbit("COM", "AAA");
            sut.AddOrbit("AAA", "BBB");
            sut.AddOrbit("BBB", "CCC");

            Assert.Equal(3, sut.Checksum("CCC"));
        }
Beispiel #4
0
        public void TestAddMultipleDirectOrbit()
        {
            OrbitMap om = new OrbitMap();

            Assert.That(om.AddOrbit("COM", "A"), Is.EqualTo(true));
            Assert.That(om.AddOrbit("COM", "B"), Is.EqualTo(true));

            int checksum = om.GetChecksum();

            Assert.That(checksum, Is.EqualTo(2));
        }
Beispiel #5
0
        public void TestAddIndirectOrbit()
        {
            OrbitMap om = new OrbitMap();

            Assert.That(om.AddOrbit("COM", "A"), Is.EqualTo(true));
            Assert.That(om.AddOrbit("A", "B"), Is.EqualTo(true));
            Assert.That(om.AddOrbit("NOTFOUND", "B"), Is.EqualTo(false));

            int checksum = om.GetChecksum();

            Assert.That(checksum, Is.EqualTo(3));
        }
Beispiel #6
0
        public void TestGetOrbitalDistance()
        {
            OrbitMap om = new OrbitMap();

            Assert.That(om.AddOrbit("COM", "A"), Is.EqualTo(true));
            Assert.That(om.AddOrbit("A", "B"), Is.EqualTo(true));
            Assert.That(om.AddOrbit("B", "C"), Is.EqualTo(true));
            Assert.That(om.AddOrbit("C", "START"), Is.EqualTo(true));
            Assert.That(om.AddOrbit("A", "END"), Is.EqualTo(true));

            Assert.That(om.GetOrbitalDistance("START", "END"), Is.EqualTo(2));
            Assert.That(om.GetOrbitalDistance("END", "START"), Is.EqualTo(2));
        }
Beispiel #7
0
        public void TestAddingOrbit()
        {
            var input = "A)BSD";

            orbitMap.AddOrbit(input);
            orbitMap.AllOrbits[0].Name.Should().Be("A");
        }
Beispiel #8
0
        public void Direct_Satellite_To_COM_Equals_1()
        {
            var sut = new OrbitMap();

            sut.AddOrbit("COM", "AAA");

            Assert.Equal(1, sut.Checksum("AAA"));
        }
Beispiel #9
0
        public void COM_CheckSum_WithSatellite_Equals_0()
        {
            var sut = new OrbitMap();

            sut.AddOrbit("COM", "AAA");

            Assert.Equal(0, sut.Checksum("COM"));
        }
        private OrbitMap PopulateOrbitMap(string oName, OrbitMap om, List <string[]> orbits)
        {
            List <string[]> availableOrbits = orbits.Where(x => oName == x[0]).ToList();

            foreach (string[] orbit in availableOrbits)
            {
                om.AddOrbit(orbit[0], orbit[1]);
                PopulateOrbitMap(orbit[1], om, orbits);
                orbits.Remove(orbit);
            }

            return(om);
        }
        private void Work(object arg)
        {
            CalculationOptions opt = arg as CalculationOptions;
            NetworkStream ns = null;
            Success = false;
            try
            {
                ns = TcpHelper.OpenStream(Host, 1);

                byte[] magic = new byte[4];
                ns.Read(magic, 0, 4);
                uint v = BitConverter.ToUInt32(magic, 0);

                bool be = (v == 0xAFDE0000); // Renderer sends 00 00 DE AF, if its reversed all is in big endian

                EndianBitConverter ec;
                if (be) ec = new BigEndianBitConverter();
                else ec = new LittleEndianBitConverter();

                using (EndianBinaryWriter bw = new EndianBinaryWriter(ec, ns))
                using (EndianBinaryReader br = new EndianBinaryReader(ec, ns))
                {
                    bw.Write((uint)0x0000FEED);

                    // Write rational coordinates
                    foreach (BigRational r in new[] { opt.MinRe, opt.MaxRe, opt.MinIm, opt.MaxIm })
                    {
                        int sign = r.Numerator.Sign;
                        byte[] num = BigInteger.Abs(r.Numerator).ToByteArray();
                        bw.Write(sign);
                        bw.Write(num.Length);
                        bw.Write(num);

                        num = BigInteger.Abs(r.Denominator).ToByteArray();
                        bw.Write(num.Length);
                        bw.Write(num);
                    }
                    bw.Write(opt.IterationCount);
                    bw.Write(opt.Width);
                    bw.Write(opt.Height);
                    bw.Write(opt.XOff);
                    bw.Write(opt.XSkip);
                    bw.Write(opt.XMax);
                    bw.Write(opt.YOff);
                    bw.Write(opt.YSkip);
                    bw.Write(opt.YMax);
                    bw.Write(opt.OrbitStart);
                    bw.Write(opt.OrbitLength);
                    bw.Write(opt.BulbChecking ? 1U : 0U);

                    int ok = br.ReadInt32();
                    if (ok != 200)
                        throw new InvalidOperationException();  // TODO Proper exception

                    // Sent parameters, now read all orbits
                    OrbitMap map = new OrbitMap();

                    int orbitsComing = 0;
                    while ((orbitsComing = br.ReadInt32()) >= 0)
                    {
                        for (int i = 0; i < orbitsComing; i++)
                        {
                            int o_x = br.ReadInt32();
                            int o_y = br.ReadInt32();

                            BigRational re, im;
                            re = ReadRational(br);
                            im = ReadRational(br);
                            BigComplex o_c = new BigComplex(re, im);

                            uint o_iter = br.ReadUInt32(); // Number of iterations before escape
                            uint o_orbs = br.ReadUInt32(); // Offset of the orbit
                            uint o_orbl = br.ReadUInt32(); // Length of the orbit

                            Orbit orbit = new Orbit(o_x, o_y, o_c, o_iter, o_orbs, o_orbl);

                            for (uint j = 0; j < o_orbl; j++)
                            {
                                re = ReadRational(br);
                                im = ReadRational(br);
                                orbit.Add(re, im);
                            }

                            map.AddOrbit(orbit);
                        }
                    }

                    Result = map; // Set the result so it can be combined with work from the other threads
                }

                ns.Close();
                Success = true;
            }
            catch (Exception) // TODO error handling ? Just log the message and be done
            {
                Success = false;
            }
            finally
            {
                if (ns != null)
                    ns.Close();

                (WaitHandle as ManualResetEvent).Set(); // Public signal that I'm done
            }
        }