static PascalsTriangleBasedCalculatorTests() { Gf27 = new PrimePowerOrderField(27, new Polynomial(new PrimeOrderField(3), 2, 2, 0, 1)); CalculatorTestsData = new TheoryData <CombinationsCountCalculatorTestCase> { new CombinationsCountCalculatorTestCase { Field = Gf27, N = 6, K = 3, Expected = Gf27.CreateElement(2) }, new CombinationsCountCalculatorTestCase { Field = Gf27, N = 4, K = 2, Expected = Gf27.Zero() }, new CombinationsCountCalculatorTestCase { Field = Gf27, N = 52, K = 5, Expected = Gf27.Zero() }, new CombinationsCountCalculatorTestCase { Field = Gf27, N = 52, K = 5, Expected = Gf27.Zero() }, new CombinationsCountCalculatorTestCase { Field = Gf27, N = 13, K = 3, Expected = Gf27.One() }, new CombinationsCountCalculatorTestCase { Field = Gf27, N = 13, K = 10, Expected = Gf27.One() }, new CombinationsCountCalculatorTestCase { Field = Gf27, N = 4, K = 3, Expected = Gf27.One() } }; }
static PascalsTriangleBasedCalcualtorTests() { Gf27 = new PrimePowerOrderField(27, new Polynomial(new PrimeOrderField(3), 2, 2, 0, 1)); CalculatorTestsData = new[] { new object[] { Gf27, 6, 3, new FieldElement(Gf27, 2) }, new object[] { Gf27, 4, 2, Gf27.Zero() }, new object[] { Gf27, 52, 5, Gf27.Zero() }, new object[] { Gf27, 52, 5, Gf27.Zero() }, new object[] { Gf27, 13, 3, Gf27.One() }, new object[] { Gf27, 13, 10, Gf27.One() }, new object[] { Gf27, 4, 3, Gf27.One() } }; }
static KotterAlgorithmBasedBuilderTests() { var gf5 = new PrimeOrderField(5); var gf8 = new PrimePowerOrderField(8, new Polynomial(new PrimeOrderField(2), 1, 1, 0, 1)); var gf27 = new PrimePowerOrderField(27, new Polynomial(new PrimeOrderField(3), 2, 2, 0, 1)); var degreeWeight = new Tuple <int, int>(1, 2); SuccessConstructionTestsData = new TheoryData <InterpolationPolynomialBuilderTestCase> { new InterpolationPolynomialBuilderTestCase { DegreeWeight = degreeWeight, MaxWeightedDegree = 3, Roots = new[] { Tuple.Create(gf5.One(), gf5.CreateElement(3)), Tuple.Create(gf5.CreateElement(2), gf5.CreateElement(4)) } }, new InterpolationPolynomialBuilderTestCase { DegreeWeight = degreeWeight, MaxWeightedDegree = 3, Roots = new[] { Tuple.Create(gf8.CreateElement(3), gf8.CreateElement(7)), Tuple.Create(gf8.CreateElement(5), gf8.CreateElement(4)) } }, new InterpolationPolynomialBuilderTestCase { DegreeWeight = degreeWeight, MaxWeightedDegree = 3, Roots = new[] { Tuple.Create(gf27.CreateElement(15), gf27.CreateElement(26)), Tuple.Create(gf27.CreateElement(10), gf27.CreateElement(9)) } } }; FailConstructionTestsData = new TheoryData <InterpolationPolynomialBuilderTestCase> { new InterpolationPolynomialBuilderTestCase { DegreeWeight = degreeWeight, MaxWeightedDegree = 2, Roots = new[] { Tuple.Create(gf27.One(), gf27.CreateElement(16)), Tuple.Create(gf27.CreateElement(13), gf27.CreateElement(26)), Tuple.Create(gf27.CreateElement(10), gf27.CreateElement(15)), Tuple.Create(gf27.CreateElement(8), gf27.CreateElement(5)) } } }; }
public void ShouldFillCombinationsCacheDuringCalculations() { // Given const int n = 4; const int k = 3; var combinationsCache = new FieldElement[5][].MakeSquare(); // When _calculator.Calculate(Gf27, n, k, combinationsCache); // Then Assert.Equal(Gf27.One(), combinationsCache[4][3]); Assert.Equal(Gf27.One(), combinationsCache[3][3]); Assert.Equal(Gf27.Zero(), combinationsCache[3][2]); Assert.Equal(Gf27.One(), combinationsCache[2][2]); Assert.Equal(new FieldElement(Gf27, 2), combinationsCache[2][1]); Assert.Equal(Gf27.One(), combinationsCache[1][1]); Assert.Equal(Gf27.One(), combinationsCache[1][0]); }
static RrFactorizatorTests() { var gf19 = new PrimeOrderField(19); var gf8 = new PrimePowerOrderField(8, new Polynomial(new PrimeOrderField(2), 1, 1, 0, 1)); FactorizationTestsData = new[] { new object[] { new BiVariablePolynomial(gf19) { [new Tuple <int, int>(0, 0)] = new FieldElement(gf19, 4), [new Tuple <int, int>(1, 0)] = new FieldElement(gf19, 12), [new Tuple <int, int>(2, 0)] = new FieldElement(gf19, 5), [new Tuple <int, int>(3, 0)] = new FieldElement(gf19, 11), [new Tuple <int, int>(4, 0)] = new FieldElement(gf19, 8), [new Tuple <int, int>(5, 0)] = new FieldElement(gf19, 13), [new Tuple <int, int>(0, 1)] = new FieldElement(gf19, 14), [new Tuple <int, int>(1, 1)] = new FieldElement(gf19, 14), [new Tuple <int, int>(2, 1)] = new FieldElement(gf19, 9), [new Tuple <int, int>(3, 1)] = new FieldElement(gf19, 16), [new Tuple <int, int>(4, 1)] = new FieldElement(gf19, 8), [new Tuple <int, int>(0, 2)] = new FieldElement(gf19, 14), [new Tuple <int, int>(1, 2)] = new FieldElement(gf19, 13), [new Tuple <int, int>(2, 2)] = new FieldElement(gf19, 1), [new Tuple <int, int>(0, 3)] = new FieldElement(gf19, 2), [new Tuple <int, int>(1, 3)] = new FieldElement(gf19, 11), [new Tuple <int, int>(2, 3)] = new FieldElement(gf19, 1), [new Tuple <int, int>(0, 4)] = new FieldElement(gf19, 17) }, 1, new[] { new Polynomial(gf19, 18, 14), new Polynomial(gf19, 14, 16), new Polynomial(gf19, 8, 8) } }, new object[] { new BiVariablePolynomial(gf8) { [new Tuple <int, int>(1, 1)] = gf8.One(), [new Tuple <int, int>(0, 2)] = gf8.One() }, 1, new [] { new Polynomial(gf8), new Polynomial(gf8, 0, 1) } }, new object[] { new BiVariablePolynomial(gf8) { [new Tuple <int, int>(2, 1)] = gf8.One(), [new Tuple <int, int>(0, 2)] = gf8.One() }, 2, new [] { new Polynomial(gf8), new Polynomial(gf8, 0, 0, 1) } } }; }
static RrFactorizatorTests() { var gf19 = new PrimeOrderField(19); var gf8 = new PrimePowerOrderField(8, new Polynomial(new PrimeOrderField(2), 1, 1, 0, 1)); FactorizationTestsData = new TheoryData <InterpolationPolynomialFactorizatorTestCase> { new InterpolationPolynomialFactorizatorTestCase { Polynomial = new BiVariablePolynomial(gf19) { [Tuple.Create(0, 0)] = gf19.CreateElement(4), [Tuple.Create(1, 0)] = gf19.CreateElement(12), [Tuple.Create(2, 0)] = gf19.CreateElement(5), [Tuple.Create(3, 0)] = gf19.CreateElement(11), [Tuple.Create(4, 0)] = gf19.CreateElement(8), [Tuple.Create(5, 0)] = gf19.CreateElement(13), [Tuple.Create(0, 1)] = gf19.CreateElement(14), [Tuple.Create(1, 1)] = gf19.CreateElement(14), [Tuple.Create(2, 1)] = gf19.CreateElement(9), [Tuple.Create(3, 1)] = gf19.CreateElement(16), [Tuple.Create(4, 1)] = gf19.CreateElement(8), [Tuple.Create(0, 2)] = gf19.CreateElement(14), [Tuple.Create(1, 2)] = gf19.CreateElement(13), [Tuple.Create(2, 2)] = gf19.CreateElement(1), [Tuple.Create(0, 3)] = gf19.CreateElement(2), [Tuple.Create(1, 3)] = gf19.CreateElement(11), [Tuple.Create(2, 3)] = gf19.CreateElement(1), [Tuple.Create(0, 4)] = gf19.CreateElement(17) }, MaxFactorDegree = 1, Expected = new[] { new Polynomial(gf19, 18, 14), new Polynomial(gf19, 14, 16), new Polynomial(gf19, 8, 8) } }, new InterpolationPolynomialFactorizatorTestCase { Polynomial = new BiVariablePolynomial(gf8) { [Tuple.Create(1, 1)] = gf8.One(), [Tuple.Create(0, 2)] = gf8.One() }, MaxFactorDegree = 1, Expected = new[] { new Polynomial(gf8), new Polynomial(gf8, 0, 1) } }, new InterpolationPolynomialFactorizatorTestCase { Polynomial = new BiVariablePolynomial(gf8) { [Tuple.Create(2, 1)] = gf8.One(), [Tuple.Create(0, 2)] = gf8.One() }, MaxFactorDegree = 2, Expected = new[] { new Polynomial(gf8), new Polynomial(gf8, 0, 0, 1) } } }; }