Ejemplo n.º 1
0
        public void Should_substruct_big_numbers_correctly(string x, string y, string z)
        {
            var i1 = Int256.Parse(x);
            var i2 = Int256.Parse(y);

            var i3 = i1 - i2;

            ("0x" + i3.ToString("X32")).Should().Be(z);
        }
Ejemplo n.º 2
0
        public void Should_sum_big_numbers_correctly(string x, string y, string z)
        {
            Int256 i1 = Int256.Parse(x);
            Int256 i2 = Int256.Parse(y);

            Int256 i3 = i1 + i2;

            ("0x" + i3.ToString("X32")).Should().Be(z);
        }
Ejemplo n.º 3
0
        public void Should_multiply_big_numbers_correctly(string x, string y, string z)
        {
            var i1 = Int256.Parse(x);
            var i2 = Int256.Parse(y);

            var i3 = i1 * i2;

            ("0x" + i3.ToString("X")).Should().Be(z);
        }
Ejemplo n.º 4
0
        public void Should_leftShift_correctly(string x, string y, string z)
        {
            //
            // X >> Y should = z
            //
            Int256 i1       = Int256.Parse(x);
            int    shifthBy = int.Parse(y);
            Int256 i3       = i1 << shifthBy;

            ("0x" + i3.ToString("X32")).Should().Be(z);
        }
Ejemplo n.º 5
0
        public void Should_rightShift_correctly(string x, string y, string z)
        {
            //
            // X >> Y should = z
            //
            var i1       = Int256.Parse(x);
            var shifthBy = int.Parse(y);
            var i3       = i1 >> shifthBy;

            ("0x" + i3.ToString("X32")).Should().Be(z);
        }
Ejemplo n.º 6
0
        //[TestCase("2852213850458175921094913949697", "51539607551", "55340232221128654847")]
        //[TestCase("2253601067072664030639173111353", "2932031007403", "768614336404564651")]
        //[TestCase("154866286100907105216716400854538488352313", "768614336404564651", "201487636602438195784363")]
        //[TestCase("170277282318432095373149951383568233665261047797485113", "201487636602438195784363", "845100400152152934331135470251")]
        //[TestCase("47928794074934470746074693488053803551576675688093033978263006055993", "845100400152152934331135470251", "56713727820156410577229101238628035243")]
        public void Should_get_prime_multipliers_for_Int256(string pqS, string expectedPs, string expectedQs)
        {
            Int256 pq = Int256.Parse(pqS);
            Int256 expectedP = Int256.Parse(expectedPs);
            Int256 expectedQ = Int256.Parse(expectedQs);
            Int256 p, q;

            pq.GetPrimeMultipliers(out p, out q);

            p.Should().Be(expectedP);
            q.Should().Be(expectedQ);
        }
Ejemplo n.º 7
0
        public void Should_compare_big_numbers_correctly(string x, string y, bool?z)
        {
            // z == null means that numbers are equal.

            Int256 i1 = Int256.Parse(x);
            Int256 i2 = Int256.Parse(y);

            bool value = z.HasValue && z.Value;

            (i1 > i2).Should().Be(value);
            (i1 < i2).Should().Be(z.HasValue && !value);
            (i1 == i2).Should().Be(!z.HasValue);
            (i1 != i2).Should().Be(z.HasValue);
        }
Ejemplo n.º 8
0
        private static SolverState LoadSave(string savePath)
        {
            if (File.Exists(savePath))
            {
                string[] save            = File.ReadAllLines(stateFile)[0].Split(';');
                string[] fileProperties  = save[0].Split(',');
                string[] primeProperties = save[1].Split(',');

                return(new SolverState()
                {
                    primeCounter = long.Parse(primeProperties[0]),
                    primeSum = Int256.Parse(primeProperties[1]),
                    groupIndex = int.Parse(fileProperties[0]),
                    part = int.Parse(fileProperties[1]) + 1
                });
            }
            return(SolverState.DEFAULT);
        }
Ejemplo n.º 9
0
        private static IEnumerable <DataUnit> GetData()
        {
            return(new List <DataUnit>
            {
                new DataUnit(int.MinValue, GetBytes(int.MinValue)),
                new DataUnit(int.MaxValue, GetBytes(int.MaxValue)),
                new DataUnit(uint.MinValue, GetBytes(uint.MinValue)),
                new DataUnit(uint.MaxValue, GetBytes(uint.MaxValue)),
                new DataUnit(long.MinValue, GetBytes(long.MinValue)),
                new DataUnit(long.MaxValue, GetBytes(long.MaxValue)),
                new DataUnit(ulong.MinValue, GetBytes(ulong.MinValue)),
                new DataUnit(ulong.MaxValue, GetBytes(ulong.MaxValue)),
                new DataUnit(double.MinValue, GetBytes(double.MinValue)),
                new DataUnit(double.MaxValue, GetBytes(double.MaxValue)),
                new DataUnit(double.Epsilon, GetBytes(double.Epsilon)),
                new DataUnit(double.NaN, GetBytes(double.NaN)),
                new DataUnit(double.PositiveInfinity, GetBytes(double.PositiveInfinity)),
                new DataUnit(double.NegativeInfinity, GetBytes(double.NegativeInfinity)),
                new DataUnit(true, GetBytes(0x997275b5)),
                new DataUnit(false, GetBytes(0xbc799737)),
                new DataUnit("P", GetBytes(0x5001)),
                new DataUnit("Pa", GetBytes(0x615002)),
                new DataUnit("Pav", GetBytes(0x76615003)),
                new DataUnit("Pave", GetBytes(0x76615004, 0x65)),
                new DataUnit("Pavel", GetBytes(0x76615005, 0x6c65)),
                new DataUnit(new string('P', 500), GetBytes(0x1F4FE, Enumerable.Repeat((byte)0x50, 500))),
                new DataUnit(new string('P', 501), GetBytes(0x1F5FE, Enumerable.Repeat((byte)0x50, 501), new byte[] { 0, 0, 0 })),
                new DataUnit(new string('P', 502), GetBytes(0x1F6FE, Enumerable.Repeat((byte)0x50, 502), new byte[] { 0, 0 })),
                new DataUnit(new string('P', 503), GetBytes(0x1F7FE, Enumerable.Repeat((byte)0x50, 503), new byte[] { 0 })),
                new DataUnit(
                    new TestObject
                {
                    TestBoolean = true,
                    TestDouble = Double.Epsilon,
                    TestInt = Int32.MaxValue,
                    TestIntVector = new List <int> {
                        1, 2, 3, 4, 5
                    },
                    TestLong = Int64.MaxValue,
                    TestString = "PPP",
                    TestInt128 = Int128.Parse("0x0102030405060708090A0B0C0D0E0F10"),
                    TestInt256 = Int256.Parse("0x0102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F20"),
                    TestUsersVector =
                        new List <IUser>
                    {
                        new User {
                            Id = 2, FirstName = "Pavel", LastName = "Durov", Key = new byte[] { 1, 2, 3, 4, 5 }
                        },
                        new NoUser {
                            Id = 3
                        },
                        new User {
                            Id = 4, FirstName = "Nikolay", LastName = "Durov", Key = new byte[] { 6, 7, 8, 9, 10 }
                        }
                    },
                    TestIntBareVector = new List <int> {
                        9, 99, 999, 9999, 99999, 999999
                    }
                },
                    GetBytes(0xA1B2C3D4, 0x997275b5, Double.Epsilon, Int32.MaxValue, 0x1CB5C415, 5, 1, 2, 3, 4, 5, Int64.MaxValue, 0x50505003, 0x090A0B0C0D0E0F10,
                             0x0102030405060708UL, 0x191A1B1C1D1E1F20, 0x1112131415161718, 0x090A0B0C0D0E0F10, 0x0102030405060708UL, 0x1cb5c415, 0x3, 0xd23c81a3, 0x2, 0x76615005, 0x6c65,
                             0x72754405, 0x766f, 0x03020105, 0x0504, 0xc67599d1, 0x3, 0xd23c81a3, 0x4, 0x6b694e07, 0x79616c6f, 0x72754405, 0x766f, 0x08070605, 0x0A09,
                             6, 9, 99, 999, 9999, 99999, 999999), "TestObject"),

                // getUsers([2,3,4])
                new DataUnit(new GetUsersFunction {
                    Arg1 = new List <int> {
                        2, 3, 4
                    }
                }, GetBytes(0x2d84d5f5, 0x1cb5c415, 0x3, 0x2, 0x3, 0x4), "GetUsersFunction"),

                // Response to getUsers([2,3,4])
                new DataUnit(
                    new List <IUser>
                {
                    new User {
                        Id = 2, FirstName = "Pavel", LastName = "Durov", Key = new byte[] { 1, 2, 3, 4, 5 }
                    },
                    new NoUser {
                        Id = 3
                    },
                    new User {
                        Id = 4, FirstName = "Nikolay", LastName = "Durov", Key = new byte[] { 6, 7, 8, 9, 10 }
                    }
                },
                    GetBytes(0x1cb5c415, 0x3, 0xd23c81a3, 0x2, 0x76615005, 0x6c65, 0x72754405, 0x766f, 0x03020105, 0x0504, 0xc67599d1, 0x3, 0xd23c81a3, 0x4, 0x6b694e07, 0x79616c6f,
                             0x72754405, 0x766f, 0x08070605, 0x0A09), "List<IUser>"),
            });
        }