add: test for custom field auto register

This commit is contained in:
h z
2024-12-12 12:33:00 +00:00
parent ae96d8b05a
commit d890865c26

View File

@@ -0,0 +1,51 @@
using System;
using Skeleton.Algebra.FieldStructures;
namespace Skeleton.Test;
public class CustomFieldStructureTest
{
[CustomFieldStructure]
public class CustomField : FieldStructure<int>
{
public override int Addition(int self, int other) => (self + other) % 7;
public override int AdditionUnit => 0;
public override int Multiplication(int self, int other) => (self * other) % 7;
public override int MultiplicationUnit => 1;
public override int AdditionInverse(int self) => (7 - self) % 7;
public override int MultiplicationInverse(int self)
{
for(int i = 0; i <= 7; i++ )
if ((i * self) % 7 == 1)
return i;
throw new DivideByZeroException();
}
public override int Conj(int self) => self;
public override bool IsEqualApprox(int self, int other, double? absTol = null, double? relTol = null) =>
(self % 7) == (other % 7);
public override string RawCSharpRepresentation(int x) => $"{x}";
public override double MaxError(int a) => (Math.Abs(a) % 7);
public override int SquareRoot(int a)
{
for (int i = 0; i <= 7; i++)
{
if ((i * i) % 7 == a)
return i;
}
throw new ArgumentException("negative number in sqrt");
}
}
[Test]
public static void CustomerFieldStructureShouldNotBeNullTest()
{
Assert.IsNotNull(FieldStructure<int>.Dispatch());
}
}