Compare commits

...

16 Commits

Author SHA1 Message Date
2b447c37b2 improve: remove unused code 2024-12-15 02:37:23 +00:00
8d378c0fbf Fix: Unitary Decomposition -> Conj inplace not handled correct 2024-12-15 01:21:59 +00:00
d890865c26 add: test for custom field auto register 2024-12-12 12:33:00 +00:00
ae96d8b05a add: auto register custom field 2024-12-12 12:16:22 +00:00
c3397b6cc3 refactor: remove unnecessary class static access 2024-12-12 11:08:29 +00:00
6867f06b48 Amend 2024-11-30 20:12:13 +00:00
33e6f36841 Change Remote 2024-11-30 20:11:27 +00:00
ccb1c521d8 adjust namespace 2024-07-10 15:45:12 +01:00
a922a8971e rename test project 2024-07-10 15:43:44 +01:00
d37b9957b0 ok 2024-06-23 03:57:46 +08:00
8b747279ce Assert Fail Test 2024-06-23 03:28:39 +08:00
dbcb96ec7c minor fix 2024-06-23 03:05:19 +08:00
7615f8939a minor update 2024-06-23 03:03:26 +08:00
ffa03575b2 minor fix 2024-06-23 02:52:01 +08:00
98a5f5db9e minor fix 2024-06-23 02:41:23 +08:00
99f1e5f5a4 minor fix 2024-06-23 02:39:19 +08:00
44 changed files with 515 additions and 96 deletions

13
.idea/.idea.Skeleton.Test/.idea/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,13 @@
# Default ignored files
/shelf/
/workspace.xml
# Rider ignored files
/projectSettingsUpdater.xml
/.idea.Skeleton.Test.iml
/modules.xml
/contentModel.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
</project>

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="UserContentModel">
<attachedFolders />
<explicitIncludes />
<explicitExcludes />
</component>
</project>

7
.idea/.idea.Skeleton.Test/.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
<mapping directory="$PROJECT_DIR$/../Skeleton" vcs="Git" />
</component>
</project>

13
.idea/.idea.SkeletonTest.dir/.idea/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,13 @@
# Default ignored files
/shelf/
/workspace.xml
# Rider ignored files
/.idea.SkeletonTest.iml
/contentModel.xml
/modules.xml
/projectSettingsUpdater.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
</project>

13
.idea/.idea.SkeletonTest/.idea/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,13 @@
# Default ignored files
/shelf/
/workspace.xml
# Rider ignored files
/contentModel.xml
/projectSettingsUpdater.xml
/.idea.SkeletonTest.iml
/modules.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
</project>

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="UserContentModel">
<attachedFolders />
<explicitIncludes />
<explicitExcludes />
</component>
</project>

7
.idea/.idea.SkeletonTest/.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/../Skeleton" vcs="Git" />
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@@ -1,5 +1,5 @@
sed -i '/^Project.*"Skeleton".*/d' ./SkeletonTest.sln sed -i '/^Project.*"Skeleton".*/d' ./Skeleton.Test.sln
sed -i '/^EndProject$/d' ./SkeletonTest.sln sed -i '/^EndProject$/d' ./Skeleton.Test.sln
sed -i '/^Project.*/aEndProject' ./SkeletonTest.sln sed -i '/^Project.*/aEndProject' ./Skeleton.Test.sln
sed -i '/.*ProjectReference.*Skeleton.csproj.*/d' ./SkeletonTest.csproj sed -i '/.*ProjectReference.*/d' ./Skeleton.Test.csproj

View File

@@ -1,10 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net6.0</TargetFramework> <TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<IsPackable>false</IsPackable> <IsPackable>false</IsPackable>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=tests/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

View File

@@ -1,6 +1,6 @@
 
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SkeletonTest", "SkeletonTest.csproj", "{58767D91-4AE1-43EB-9DBC-498EE84DE6AC}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Skeleton.Test", "Skeleton.Test.csproj", "{58767D91-4AE1-43EB-9DBC-498EE84DE6AC}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Skeleton", "..\Skeleton\Skeleton.csproj", "{61DBA845-169F-473E-B084-09B6A0E3762C}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Skeleton", "..\Skeleton\Skeleton.csproj", "{61DBA845-169F-473E-B084-09B6A0E3762C}"
EndProject EndProject

View File

@@ -0,0 +1,16 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AAssert_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F25288f22b7c548d8adf4cb3c0171568e75600_003F20_003Ffd54a947_003FAssert_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AAssert_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F967970eb58b63e4977b87c01850b7af6afd5431576aa402786bd2d7aee5e95_003FAssert_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AAssert_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F967970eb58b63e4977b87c01850b7af6afd5431576aa402786bd2d7aee5e95_003FAssert_002Ecs_002Fz_003A2_002D1/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AComplex_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fc9562abf75b040988727ba7f259b2b4747c00_003F5d_003F72a1a085_003FComplex_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AConsole_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F98766785e56e4531a13014935c13e8202da00_003Fae_003F501234fb_003FConsole_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/Environment/Hierarchy/Build/BuildTool/CustomBuildToolPath/@EntryValue">/usr/lib/dotnet/sdk/8.0.110/MSBuild.dll</s:String>
<s:String x:Key="/Default/Environment/Hierarchy/Build/BuildTool/DotNetCliExePath/@EntryValue">/usr/lib/dotnet/dotnet</s:String>
<s:Int64 x:Key="/Default/Environment/Hierarchy/Build/BuildTool/MsbuildVersion/@EntryValue">4294967294</s:Int64>
<s:Boolean x:Key="/Default/Environment/Hierarchy/Build/BuildTool/RecentBuildToolPaths/=_002Fusr_002Flib_002Fdotnet_002Fsdk_002F8_002E0_002E110_002FMSBuild_002Edll/@EntryIndexedValue">True</s:Boolean>
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=996f1696_002D38c8_002D48d8_002Da948_002Ddaa24c1498f3/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" IsActive="True" Name="All tests from Solution" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;
&lt;Solution /&gt;
&lt;/SessionState&gt;</s:String>
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=d01aff50_002D0713_002D48c1_002Da4de_002Da093a716f694/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" Name="All tests from &amp;lt;Skeleton.Test&amp;gt;" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;
&lt;Project Location="/home/hzhang/RiderProjects/Marshmallow/Skeleton.Test" Presentation="&amp;lt;Skeleton.Test&amp;gt;" /&gt;
&lt;/SessionState&gt;</s:String></wpf:ResourceDictionary>

View File

@@ -0,0 +1,4 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=57175bc5_002D3ffe_002D4664_002D9725_002D1923c035c70a/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" IsActive="True" Name="All tests from &amp;lt;SkeletonTest&amp;gt;" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;
&lt;Project Location="/home/hzhang/RiderProjects/SkeletonTest" Presentation="&amp;lt;SkeletonTest&amp;gt;" /&gt;
&lt;/SessionState&gt;</s:String></wpf:ResourceDictionary>

View File

@@ -9,6 +9,8 @@ for x in d['data']:
w = open('SkeletonTest.csproj', 'r').read() w = open('SkeletonTest.csproj', 'r').read()
s = w.split('<ItemGroup>') s = w.split('<ItemGroup>')
w = s[0] + '<ItemGroup>\n<PackageReference Include="Skeleton" Version="'+version+'"/>' + s[1] s[1] = '\n<PackageReference Include="Skeleton" Version="'+version+'"/>\n' + s[1]
w = '<ItemGroup>'.join(s)
print(w)
with open('SkeletonTest.csproj', 'w') as f: with open('SkeletonTest.csproj', 'w') as f:
f.write(w) f.write(w)

View File

@@ -2,11 +2,10 @@ using System.Numerics;
using Skeleton.Algebra.AffineSpaces; using Skeleton.Algebra.AffineSpaces;
using Skeleton.Algebra.DimensionProviders; using Skeleton.Algebra.DimensionProviders;
namespace SkeletonTest.tests; namespace Skeleton.Test;
using AffineC2Space = Algebra.CategoryOf<IDim2>.OnField<Complex>.FAffineSpace;
[TestFixture]
using AffineC2Space = Skeleton.Algebra.CategoryOf<IDim2>.OnField<Complex>.FAffineSpace; public class AffineSpaceTest : BaseTest
public static class AffineSpaceTest
{ {
[Test] [Test]
public static void BasicAffineSpaceTest() public static void BasicAffineSpaceTest()

View File

@@ -4,9 +4,9 @@ using System.Numerics;
using Skeleton.Algebra.Extensions; using Skeleton.Algebra.Extensions;
using Skeleton.Analysis.AnalyticFunctions.Polynomials.Implements; using Skeleton.Analysis.AnalyticFunctions.Polynomials.Implements;
namespace SkeletonTest.tests; namespace Skeleton.Test;
[TestFixture]
public static class AlgebraMiscTest public class AlgebraMiscTest : BaseTest
{ {
private static readonly Complex ii = new Complex(0, 1); private static readonly Complex ii = new Complex(0, 1);

17
tests/BaseTest.cs Normal file
View File

@@ -0,0 +1,17 @@
using System;
using Skeleton.Algebra;
namespace Skeleton.Test;
public class BaseTest
{
protected static int Seed = 517515;
protected static class Theory<TDim, TField>
{
public static readonly Action<CategoryOf<TDim>.OnField<TField>.FMatrix> OnFail
= x => Console.WriteLine(x.CSharpRepresentation);
}
//protected static Action<TMatrix> TheoryOnFail<TMatrix>() = x => Console.WriteLine();
}

View File

@@ -1,10 +1,11 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Skeleton.DataStructure; using Skeleton.DataStructure;
namespace SkeletonTest.tests; namespace Skeleton.Test;
[TestFixture]
public static class CacheItemTest public class CacheItemTest : BaseTest
{ {
private class TestClass private class TestClass
@@ -161,5 +162,33 @@ public static class CacheItemTest
Assert.That(a.BB.Get, Is.EqualTo(0)); Assert.That(a.BB.Get, Is.EqualTo(0));
Assert.That(b.BA.Get, Is.EqualTo(1)); Assert.That(b.BA.Get, Is.EqualTo(1));
} }
[Test]
public static void Test4()
{
CacheItem<int> x = new CacheItem<int>(s => 1);
CacheItem<int> w = new CacheItem<int>(a => x.GetFrom(a) + x.GetFrom(a));
CacheItem<int> g = new CacheItem<int>(a => w.GetFrom(a) + w.GetFrom(a) + x.GetFrom(a));
Assert.That(g.Get, Is.EqualTo(5));
x.Assign(2);
Console.WriteLine(g.Get);
Assert.That(g.Get, Is.EqualTo(10));
}
[Test]
public static void Test5()
{
CacheItem<int> x1 = new CacheItem<int>(x => 1);
CacheItem<int> x2 = new CacheItem<int>(x => x1.GetFrom(x));
CacheItem<int> x3 = new CacheItem<int>(x => x2.GetFrom(x));
CacheItem<int> x4 = new CacheItem<int>(x => x3.GetFrom(x));
Console.WriteLine(x4.Get);
x1.Assign(3);
Assert.IsTrue(x2.Expired);
Assert.IsTrue(x3.Expired);
Assert.IsTrue(x4.Expired);
Console.WriteLine(x4.Get);
}
} }

View File

@@ -4,22 +4,31 @@ using System.Numerics;
using Skeleton.Algebra.Extensions; using Skeleton.Algebra.Extensions;
using Skeleton.Samples; using Skeleton.Samples;
using Skeleton.Utils; using Skeleton.Utils;
using Skeleton.Utils.Helpers;
namespace SkeletonTest.tests; namespace Skeleton.Test;
[TestFixture]
public class CayleySU3Test public class CayleySU3Test : BaseTest
{ {
[DatapointSource] [DatapointSource]
private static readonly LieSU3[] Data = 40.ScaleSamples(-1, 1).LieSU3LogSU3Samples().ToArray(); private static readonly LieSU3[] Data = 40
.WithSeed(Seed)
.ScaleSamples(-1, 1)
.LieSU3LogSU3Samples()
.ToArray();
private static Action<LieSU3> OnFail = x => Console.WriteLine(x.CSharpRepresentation); private static Action<LieSU3> OnFail = x => Console.WriteLine(x.CSharpRepresentation);
[Theory] [Theory]
public static void TestCayleyForLieSU3(LieSU3 data) public static void TestCayleyForLieSU3(LieSU3 data)
{ {
Action<LieSU3> rawTest = x => Action<LieSU3> rawTest = x =>
{ {
Assert.IsTrue(x.Property.IsSkewHermitian);
U3 cN = x.CayleyNegative(); U3 cN = x.CayleyNegative();
Assert.IsTrue((cN * cN.Hermitian()).IsEqualApprox(C33.One)); Assert.IsTrue(cN.Property.IsUnitary);
Console.WriteLine(cN.Representation);
U3 h =cN.Hermitian();
U3 xx = cN * cN.Hermitian();
Assert.IsTrue((xx).IsEqualApprox(C33.One));
}; };
rawTest.OnFail(OnFail)(data); rawTest.OnFail(OnFail)(data);
} }

View File

@@ -4,13 +4,18 @@ using System.Numerics;
using Skeleton.Algebra.Extensions; using Skeleton.Algebra.Extensions;
using Skeleton.Samples; using Skeleton.Samples;
using Skeleton.Utils; using Skeleton.Utils;
using Skeleton.Utils.Helpers;
namespace SkeletonTest.tests; namespace Skeleton.Test;
[TestFixture]
public static class CayleySU4Test public class CayleySU4Test : BaseTest
{ {
[DatapointSource] [DatapointSource]
private static readonly LieSU4[] Data = 40.ScaleSamples(-1, 1).LieSU4LogSU4Samples().ToArray(); private static readonly LieSU4[] Data = 80
.WithSeed(Seed)
.ScaleSamples(-1, 1)
.LieSU4LogSU4Samples()
.ToArray();
private static Action<LieSU4> OnFail = x => Console.WriteLine(x.CSharpRepresentation); private static Action<LieSU4> OnFail = x => Console.WriteLine(x.CSharpRepresentation);
[Theory] [Theory]
public static void TestCayleyForLieSU4(LieSU4 data) public static void TestCayleyForLieSU4(LieSU4 data)

View File

@@ -3,13 +3,18 @@ using System.Linq;
using Skeleton.Algebra.Extensions; using Skeleton.Algebra.Extensions;
using Skeleton.Samples; using Skeleton.Samples;
using Skeleton.Utils; using Skeleton.Utils;
using Skeleton.Utils.Helpers;
namespace SkeletonTest.tests; namespace Skeleton.Test;
[TestFixture]
public static class CayleyTransformationTest public class CayleyTransformationTest : BaseTest
{ {
[DatapointSource] [DatapointSource]
private static readonly LieSU2[] Data = 40.ScaleSamples(-1, 1).LieSU2LogSU2Samples().ToArray(); private static readonly LieSU2[] Data = 40
.WithSeed(Seed)
.ScaleSamples(-1, 1)
.LieSU2LogSU2Samples()
.ToArray();
private static Action<LieSU2> OnFail = x => Console.WriteLine(x.CSharpRepresentation); private static Action<LieSU2> OnFail = x => Console.WriteLine(x.CSharpRepresentation);
[Theory] [Theory]
public static void TestCayleyForLieSU2(LieSU2 data) public static void TestCayleyForLieSU2(LieSU2 data)

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());
}
}

View File

@@ -2,18 +2,21 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Numerics; using System.Numerics;
using Skeleton.Algebra.Extensions; using Skeleton.Algebra.Extensions;
using Skeleton.Algebra.ScalarFieldStructure; using Skeleton.Algebra.FieldStructures;
using Skeleton.DataStructure.Packs.MatrixDecompositions; using Skeleton.DataStructure.Packs.MatrixDecompositions;
using Skeleton.Samples; using Skeleton.Samples;
using Skeleton.Utils; using Skeleton.Utils;
using Skeleton.Utils.Helpers;
namespace SkeletonTest.tests; namespace Skeleton.Test;
[TestFixture]
public static class DecompositionTest public class DecompositionTest : BaseTest
{ {
[DatapointSource] [DatapointSource]
public static readonly IEnumerable<C44> TestMatrices = public static readonly IEnumerable<C44> TestMatrices = 100
100.ScaleSamples(-1, 1).C44InvertibleSamples(); .WithSeed(Seed)
.ScaleSamples(-1, 1)
.C44InvertibleSamples();
private static readonly Action<C44> OnFail = x => private static readonly Action<C44> OnFail = x =>
{ {

View File

@@ -1,6 +1,6 @@
namespace SkeletonTest.tests; namespace Skeleton.Test;
[TestFixture]
public class DraftTest public class DraftTest : BaseTest
{ {
[Test] [Test]
public void QRDraftTest() public void QRDraftTest()

View File

@@ -4,15 +4,19 @@ using System.Numerics;
using Skeleton.Algebra.Extensions; using Skeleton.Algebra.Extensions;
using Skeleton.DataStructure.Packs.MatrixDecompositions; using Skeleton.DataStructure.Packs.MatrixDecompositions;
using Skeleton.Samples; using Skeleton.Samples;
using Skeleton.Utils.Helpers;
namespace SkeletonTest.tests; namespace Skeleton.Test;
[TestFixture]
public class EigenDecompositionTest public class EigenDecompositionTest : BaseTest
{ {
private static readonly Complex I = Complex.ImaginaryOne; private static readonly Complex I = Complex.ImaginaryOne;
[DatapointSource] [DatapointSource]
public static readonly C22[] DataPoints = public static readonly C22[] DataPoints = 30
30.ScaleSamples(-1, 1).C22InvertibleSamples().ToArray(); .WithSeed(Seed)
.ScaleSamples(-1, 1)
.C22InvertibleSamples()
.ToArray();
[Theory] [Theory]
public static void DecompositionIdentityTest(C22 data) public static void DecompositionIdentityTest(C22 data)
@@ -28,6 +32,9 @@ public class EigenDecompositionTest
{ {
U2 unitaryData = new U2(data); U2 unitaryData = new U2(data);
Console.WriteLine(data.Representation); Console.WriteLine(data.Representation);
Console.WriteLine(unitaryData.Representation);
Console.WriteLine(unitaryData.Hermitian().Representation);
Console.WriteLine((unitaryData * unitaryData.Hermitian()).Representation);
Assert.IsTrue((unitaryData * unitaryData.Hermitian()).IsEqualApprox(U2.One)); Assert.IsTrue((unitaryData * unitaryData.Hermitian()).IsEqualApprox(U2.One));
Assert.IsTrue(unitaryData.Det().Magnitude.IsEqualApprox(1)); Assert.IsTrue(unitaryData.Det().Magnitude.IsEqualApprox(1));
JDPair<C22> decomp = unitaryData.EigenDecomposition(); JDPair<C22> decomp = unitaryData.EigenDecomposition();
@@ -82,6 +89,9 @@ public class EigenDecompositionTest
0.8666666666666667 - 0.8666666666666667 * I, -0.4 + 0.46666666666666656 * I, 0.8666666666666667 - 0.8666666666666667 * I, -0.4 + 0.46666666666666656 * I,
-0.8666666666666667 - 0.6 * I, 0.6666666666666667 -0.8666666666666667 - 0.6 * I, 0.6666666666666667
); );
Console.WriteLine(m.PythonRepresentation);
Assert.IsTrue((m * m.Hermitian()).IsEqualApprox(C22.One)); Assert.IsTrue((m * m.Hermitian()).IsEqualApprox(C22.One));
} }
} }

View File

@@ -3,9 +3,9 @@ using System.Numerics;
using Skeleton.Algebra.Matrices; using Skeleton.Algebra.Matrices;
using Skeleton.Constants; using Skeleton.Constants;
namespace SkeletonTest.tests; namespace Skeleton.Test;
[TestFixture]
public static class EigenValueTest public class EigenValueTest : BaseTest
{ {
[Test] [Test]
public static void AlgebraicMultiplicityTest() public static void AlgebraicMultiplicityTest()

View File

@@ -1,8 +1,8 @@
using Skeleton.Algebra.ScalarFieldStructure; using Skeleton.Algebra.FieldStructures;
namespace SkeletonTest.tests; namespace Skeleton.Test;
[TestFixture]
public static class FieldStructureTest public class FieldStructureTest : BaseTest
{ {
[Test] [Test]
public static void EqualTest() public static void EqualTest()

15
tests/GlobalSetUp.cs Normal file
View File

@@ -0,0 +1,15 @@
using Skeleton.Utils.RandomEngines;
namespace Skeleton.Test;
[SetUpFixture]
public class GlobalSetUp
{
private const int RandomSeed = 33659722;
/*[SetUp]
public void SetUp()
{
RandomSource.SetSeed(RandomSeed);
}*/
}

View File

@@ -3,13 +3,17 @@ using System.Numerics;
using Skeleton.Samples; using Skeleton.Samples;
using Skeleton.Utils.Helpers; using Skeleton.Utils.Helpers;
namespace SkeletonTest.tests; namespace Skeleton.Test;
[TestFixture]
public static class JordanPowerTest public class JordanPowerTest : BaseTest
{ {
private static readonly Complex ii = new Complex(0, 1); private static readonly Complex ii = new Complex(0, 1);
[DatapointSource] [DatapointSource]
public static readonly Complex[] Basic0TestData = 10.ScaleSamples(-1, 1).UCSamples().ToArray(); public static readonly Complex[] Basic0TestData = 10
.WithSeed(Seed)
.ScaleSamples(-1, 1)
.UCSamples()
.ToArray();
[Theory] [Theory]
public static void J22TestBasic0(Complex eigenValue) public static void J22TestBasic0(Complex eigenValue)
{ {

View File

@@ -3,9 +3,9 @@ using System.Collections.Generic;
using System.Numerics; using System.Numerics;
using Skeleton.Constants; using Skeleton.Constants;
namespace SkeletonTest.tests; namespace Skeleton.Test;
[TestFixture]
public static class LieSU3FastEigenValueTest public class LieSU3FastEigenValueTest : BaseTest
{ {
private static IEnumerable<Complex> FastEigen(LieSU3 a) private static IEnumerable<Complex> FastEigen(LieSU3 a)
{ {

View File

@@ -2,9 +2,9 @@ using System;
using System.Linq; using System.Linq;
using Skeleton.DataStructure.Link; using Skeleton.DataStructure.Link;
namespace SkeletonTest.tests; namespace Skeleton.Test;
[TestFixture]
public static class LinkTest public class LinkTest : BaseTest
{ {
private class TestObj private class TestObj
{ {

View File

@@ -1,8 +1,8 @@
using Skeleton.Constants; using Skeleton.Constants;
namespace SkeletonTest.tests; namespace Skeleton.Test;
[TestFixture]
public static class MatrixExpLogTest public class MatrixExpLogTest : BaseTest
{ {
[Test] [Test]
public static void ExpTestCase0() public static void ExpTestCase0()

View File

@@ -1,8 +1,8 @@
using System; using System;
namespace SkeletonTest.tests; namespace Skeleton.Test;
[TestFixture]
public static class MiscTest public class MiscTest : BaseTest
{ {
[Test] [Test]
public static void LatexStringTest() public static void LatexStringTest()

View File

@@ -1,9 +1,9 @@
using System; using System;
using Skeleton.Constants; using Skeleton.Constants;
namespace SkeletonTest.tests; namespace Skeleton.Test;
[TestFixture]
public static class MultiplicationTest public class MultiplicationTest : BaseTest
{ {
[Test] [Test]
public static void Dim2MultiplicationTest() public static void Dim2MultiplicationTest()

View File

@@ -1,12 +1,14 @@
using System; using System;
using System.Numerics; using System.Numerics;
namespace SkeletonTest.tests; namespace Skeleton.Test;
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
public static class REFFTest
[TestFixture]
public class REFFTest : BaseTest
{ {
private static readonly Complex ii = new Complex(0, 1); private static readonly Complex ii = new Complex(0, 1);

40
tests/RandomFixTest.cs Normal file
View File

@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Skeleton.Samples;
using Skeleton.Utils.Helpers;
using Skeleton.Utils.RandomEngines;
namespace Skeleton.Test;
public class RandomFixTest : BaseTest
{
[DatapointSource] private static readonly IEnumerable<LieSU3> x =
40.WithSeed(771202).ScaleSamples(-1, 1).LieSU3LogSU3Samples().ToArray();
[Test]
public static void DatapointTest()
{
/*
Assert.AreEqual(x.Count(), 36);
*/
}
[Test]
public static void Test(){
Console.WriteLine(RandomSource.Rnd.Value.NextDouble());
Console.WriteLine(RandomSource.Rnd.Value.NextDouble());
Console.WriteLine(RandomSource.Rnd.Value.NextDouble());
}
[Test]
public static void SampleTest()
{
/*RandomSource.SetSeed(22222);
LieSU3[] a = 40.ScaleSamples(-1, 1).LieSU3LogSU3Samples().ToArray();
RandomSource.SetSeed(22222);
LieSU3[] b = 40.ScaleSamples(-1, 1).LieSU3LogSU3Samples().ToArray();
Assert.AreEqual(a.Length, b.Length);
Console.WriteLine(a.Length);*/
}
}

View File

@@ -3,9 +3,9 @@ using System.Numerics;
using Skeleton.Algebra.Extensions; using Skeleton.Algebra.Extensions;
using Skeleton.Constants; using Skeleton.Constants;
namespace SkeletonTest.tests; namespace Skeleton.Test;
[TestFixture]
public static class SUTestFix public class SUTestFix : BaseTest
{ {
[Test] [Test]
public static void Dim2Test() public static void Dim2Test()
@@ -24,6 +24,7 @@ public static class SUTestFix
-0.5330307462242154 + 0.669854044098976 * AlgebraConstant.I -0.5330307462242154 + 0.669854044098976 * AlgebraConstant.I
); );
Console.WriteLine(y.Det()); Console.WriteLine(y.Det());
Console.WriteLine((x.U * x.U.Hermitian()).Representation);
Assert.IsTrue((x.U * x.U.Hermitian()).IsEqualApprox(C22.One)); Assert.IsTrue((x.U * x.U.Hermitian()).IsEqualApprox(C22.One));
Assert.IsTrue(x.D.Det().IsEqualApprox(1)); Assert.IsTrue(x.D.Det().IsEqualApprox(1));
Console.WriteLine(x.D.PythonRepresentation); Console.WriteLine(x.D.PythonRepresentation);

View File

@@ -0,0 +1,119 @@
using System;
using System.Numerics;
using Skeleton.Algebra;
using Skeleton.Algebra.DimensionProviders;
using Skeleton.Constants;
using Skeleton.DataStructure.Packs.MatrixDecompositions;
namespace Skeleton.Test;
[TestFixture]
public class UnitaryConjugateTest
{
[Test]
public void UnitaryDecompositionShouldMatchTest()
{
C33 x = new C33(
-0.29637473524541746 - 0.4164563198193952 * AlgebraConstant.I,
0.47019945345152797 - 0.18885780773580182 * AlgebraConstant.I,
-0.5414450753609832 - 0.4345210959080704 * AlgebraConstant.I,
0.05140609295069032 - 0.17133718304221346 * AlgebraConstant.I,
-0.46675346988465705 + 0.6421597806755671 * AlgebraConstant.I,
-0.5775735169777234 + 0.06466707225491593 * AlgebraConstant.I,
-0.7911152098361764 - 0.28436571184174053 * AlgebraConstant.I,
-0.300392405520825 + 0.15093581274788961 * AlgebraConstant.I,
0.41395268302160826 - 0.09433358918942991 * AlgebraConstant.I
);
JDPair<C33> jdV1 = x.InternalUnitaryDecompositionV1();
Console.WriteLine($"j1 = {jdV1.J.PythonRepresentation}");
Console.WriteLine($"d1 = {jdV1.D.PythonRepresentation}");
//x.TestInternalUnitaryDecomposition();
/*
SU3 o = new SU3(
-0.29637473524541746 - 0.4164563198193952 * AlgebraConstant.I,
0.47019945345152797 - 0.18885780773580182 * AlgebraConstant.I,
-0.5414450753609832 - 0.4345210959080704 * AlgebraConstant.I,
0.05140609295069032 - 0.17133718304221346 * AlgebraConstant.I,
-0.46675346988465705 + 0.6421597806755671 * AlgebraConstant.I,
-0.5775735169777234 + 0.06466707225491593 * AlgebraConstant.I,
-0.7911152098361764 - 0.28436571184174053 * AlgebraConstant.I,
-0.300392405520825 + 0.15093581274788961 * AlgebraConstant.I,
0.41395268302160826 - 0.09433358918942991 * AlgebraConstant.I
);
Assert.IsTrue(x.IsEqualApprox(o.U * o.D * o.U.Hermitian()));
*/
/*Console.WriteLine(o.U.PythonRepresentation);
Console.WriteLine(o.D.PythonRepresentation);
Assert.IsTrue(x.TestEqual(o.U.Hermitian() * o.D * o.U));
SU3 ox = new SU3(x.Copy());
Assert.IsTrue(x.TestEqual(ox));
Assert.IsTrue(x.TestEqual(o));
Assert.IsTrue(x.TestEqual(o.U * o.D * o.U.Hermitian()));
Assert.IsTrue(o.TestEqual(o.U * o.D * o.U.Hermitian()));
Console.WriteLine(o.PythonRepresentation);
Console.WriteLine((x-o).PythonRepresentation);*/
}
[Test]
public void UnitaryConjugateShouldEqualTest()
{
SU3 a = new SU3(
-0.46622721713303866 - 0.060475409668431644 * AlgebraConstant.I,
-0.1425326880495955 - 0.11337596851236675 * AlgebraConstant.I,
0.5124598007869261 - 0.6951188258193564 * AlgebraConstant.I,
-0.07977662445969419 - 0.15645179782505836 * AlgebraConstant.I,
0.13131935891627658 + 0.9689404759173665 * AlgebraConstant.I,
0.10764157750707277 - 0.038488908035408866 * AlgebraConstant.I,
-0.7605308190317062 + 0.4119785252654601 * AlgebraConstant.I,
-0.09712183746948519 + 0.036155931610674256 * AlgebraConstant.I,
0.003739510338355845 + 0.4910322610393366 * AlgebraConstant.I
);
SU3 b = new SU3(
0.671500127639027 + 0.7392727634547986 * AlgebraConstant.I,
0.018353719975610416 + 0.0009182549015047939 * AlgebraConstant.I,
-0.040341093124168115 - 0.024459226709268145 * AlgebraConstant.I,
-0.003595329870842521 + 0.011339024383085235 * AlgebraConstant.I,
0.5491128634189678 + 0.6130727033953424 * AlgebraConstant.I,
0.07005362848802227 + 0.563531643161386 * AlgebraConstant.I,
0.007924807904311937 - 0.04857012809860661 * AlgebraConstant.I,
0.3699849579680355 + 0.43056979948404905 * AlgebraConstant.I,
-0.08442219397132456 - 0.8174177707212459 * AlgebraConstant.I
);
//Assert.IsTrue(a.TestEqual(a.U * a.D * a.U.Hermitian()));
//Assert.IsTrue(b.TestEqual(b.U * b.D * b.U.Hermitian()));
SU3 ax = a.ConjugateOn(b);
SU3 bx = a * b * a.Hermitian();
CategoryOf<IDim3>.OnField<Complex>.FMatrix wx = a.AsMatrix * b.AsMatrix * a.AsMatrix.Hermitian();
//Assert.IsTrue(wx.TestEqual(bx));
Console.WriteLine($"a = {a.PythonRepresentation}");
Console.WriteLine($"b = {b.PythonRepresentation}");
Console.WriteLine($"ax = {ax.PythonRepresentation}");
Console.WriteLine($"bx = {bx.PythonRepresentation}");
Console.WriteLine($"wx = {wx.PythonRepresentation}");
Assert.IsTrue(a.AsMatrix.Hermitian().IsEqualApprox(a.Hermitian()));
Assert.IsTrue(bx.IsEqualApprox(ax));
Assert.IsTrue(bx.IsEqualApprox(wx));
Assert.IsTrue(ax.IsEqualApprox(wx));
}
}

View File

@@ -6,15 +6,17 @@ using Skeleton.Constants;
using Skeleton.DataStructure.Packs.MatrixDecompositions; using Skeleton.DataStructure.Packs.MatrixDecompositions;
using Skeleton.Samples; using Skeleton.Samples;
using Skeleton.Utils; using Skeleton.Utils;
using Skeleton.Utils.Helpers;
namespace SkeletonTest.tests; namespace Skeleton.Test;
[TestFixture]
public static class UnitaryMatrixFixTest public class UnitaryMatrixFixTest : BaseTest
{ {
private static Complex I = Complex.ImaginaryOne; private static Complex I = Complex.ImaginaryOne;
[DatapointSource] [DatapointSource]
public static readonly ((SU2, SU3), SU4)[] DataSource = public static readonly ((SU2, SU3), SU4)[] DataSource = 20
20.ScaleSamples(-1, 1).SU2U2FixSamples() .WithSeed(Seed)
.ScaleSamples(-1, 1).SU2U2FixSamples()
.Zip(20.ScaleSamples(-1, 1).SU3U3FixSamples()) .Zip(20.ScaleSamples(-1, 1).SU3U3FixSamples())
.Zip(20.ScaleSamples(-1, 1).SU4U4FixSamples()) .Zip(20.ScaleSamples(-1, 1).SU4U4FixSamples())
.ToArray(); .ToArray();
@@ -129,8 +131,8 @@ public static class UnitaryMatrixFixTest
Complex det = detTest.Det(); Complex det = detTest.Det();
Console.WriteLine(det); Console.WriteLine(det);
SU2 s = new SU2(detTest); SU2 s = new SU2(detTest.Copy());
Assert.IsTrue(s.IsEqualApprox(detTest)); Assert.IsFalse(s.IsEqualApprox(detTest));
} }
@@ -149,7 +151,7 @@ public static class UnitaryMatrixFixTest
0.3738133333164022 + 0.17859171769725135 * I 0.3738133333164022 + 0.17859171769725135 * I
); );
Assert.IsTrue((a * a.Hermitian()).IsEqualApprox(C33.One)); Assert.IsTrue((a * a.Hermitian()).IsEqualApprox(C33.One));
SU3 x = new SU3(a); SU3 x = new SU3(a.Copy());
Assert.IsTrue(x.IsEqualApprox(a)); Assert.IsTrue(x.IsEqualApprox(a));
Assert.IsTrue(C33.One.IsEqualApprox(SU3.One)); Assert.IsTrue(C33.One.IsEqualApprox(SU3.One));
} }
@@ -162,7 +164,7 @@ public static class UnitaryMatrixFixTest
0.23603845886157196+ 0.2882268492733082*I, 0.2598386072534029+ -0.5491251329056467*I, 0.6806580836521512+ -0.16988581178893247*I 0.23603845886157196+ 0.2882268492733082*I, 0.2598386072534029+ -0.5491251329056467*I, 0.6806580836521512+ -0.16988581178893247*I
); );
Assert.IsTrue((a * a.Hermitian()).IsEqualApprox(C33.One)); Assert.IsTrue((a * a.Hermitian()).IsEqualApprox(C33.One));
SU3 x = new (a); SU3 x = new (a.Copy());
Assert.IsTrue(x.IsEqualApprox(a)); Assert.IsTrue(x.IsEqualApprox(a));
Assert.IsTrue(C33.One.IsEqualApprox(SU3.One)); Assert.IsTrue(C33.One.IsEqualApprox(SU3.One));
SU3 w = x * x.Hermitian(); SU3 w = x * x.Hermitian();

View File

@@ -5,13 +5,14 @@ using Skeleton.Samples;
using Skeleton.Utils; using Skeleton.Utils;
using Skeleton.Utils.Helpers; using Skeleton.Utils.Helpers;
namespace SkeletonTest.tests; namespace Skeleton.Test;
[TestFixture]
public static class UnitaryTest public class UnitaryTest : BaseTest
{ {
[DatapointSource] [DatapointSource]
public static readonly (((U2, U3), U4),((U2, U3), U4))[] DataSource = public static readonly (((U2, U3), U4),((U2, U3), U4))[] DataSource =
20.ScaleSamples(-1, 1).U2FixSamples() 20.WithSeed(Seed)
.ScaleSamples(-1, 1).U2FixSamples()
.Zip(20.ScaleSamples(-1, 1).U3FixSamples()) .Zip(20.ScaleSamples(-1, 1).U3FixSamples())
.Zip(20.ScaleSamples(-1, 1).U4FixSamples()) .Zip(20.ScaleSamples(-1, 1).U4FixSamples())
.ShuffleZip() .ShuffleZip()

View File

@@ -1,12 +1,13 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Numerics; using System.Numerics;
namespace SkeletonTest.tests; namespace Skeleton.Test;
/// <summary> /// <summary>
/// test for vector spaces /// test for vector spaces
/// </summary> /// </summary>
public static class VectorSpaceTest [TestFixture]
public class VectorSpaceTest : BaseTest
{ {
private static readonly Complex ii = new Complex(0, 1); private static readonly Complex ii = new Complex(0, 1);
[Test] [Test]