Skip to content

Commit 8cdec37

Browse files
authored
Add T1HA Unit Tests
Signed-off-by: Xen <lordofxen@deskasoft.com>
1 parent 4979ae1 commit 8cdec37

File tree

6 files changed

+822
-0
lines changed

6 files changed

+822
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// *
2+
// *****************************************************************************
3+
// *
4+
// * Copyright (c) 2025 Deskasoft International
5+
// *
6+
// * Permission is hereby granted, free of charge, to any person obtaining a copy
7+
// * of this software and associated documentation files (the "Software"), to deal
8+
// * in the Software without restriction, including without limitation the rights
9+
// * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
// * copies of the Software, and to permit persons to whom the Software is
11+
// * furnished to do so, subject to the following conditions:
12+
// *
13+
// * The above copyright notice and this permission notice shall be included in all
14+
// * copies or substantial portions of the Software.
15+
// *
16+
// * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
// * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
// * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
// * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
// * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
// * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
// * SOFTWARE.
23+
// *
24+
// *
25+
// * Please refer to LICENSE file.
26+
// *
27+
// ******************************************************************************
28+
// *
29+
30+
using HashifyNet.Algorithms.T1HA;
31+
32+
namespace HashifyNet.UnitTests.Algorithms.T1HA
33+
{
34+
public class T1HA0Config_Tests
35+
{
36+
[Fact]
37+
public void T1HA0Config_Defaults_HaventChanged()
38+
{
39+
var t1HAConfig = new T1HA0Config();
40+
Assert.Equal(64, t1HAConfig.HashSizeInBits);
41+
}
42+
43+
[Fact]
44+
public void T1HA0Config_Clone_Works()
45+
{
46+
var t1HAConfig = new T1HA0Config()
47+
{
48+
Seed = 1990L
49+
};
50+
51+
var t1haConfigClone = t1HAConfig.Clone();
52+
53+
Assert.IsType<T1HA0Config>(t1haConfigClone);
54+
55+
Assert.Equal(t1HAConfig.HashSizeInBits, t1haConfigClone.HashSizeInBits);
56+
Assert.Equal(t1HAConfig.Seed, t1haConfigClone.Seed);
57+
}
58+
}
59+
}
Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
// *
2+
// *****************************************************************************
3+
// *
4+
// * Copyright (c) 2025 Deskasoft International
5+
// *
6+
// * Permission is hereby granted, free of charge, to any person obtaining a copy
7+
// * of this software and associated documentation files (the "Software"), to deal
8+
// * in the Software without restriction, including without limitation the rights
9+
// * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
// * copies of the Software, and to permit persons to whom the Software is
11+
// * furnished to do so, subject to the following conditions:
12+
// *
13+
// * The above copyright notice and this permission notice shall be included in all
14+
// * copies or substantial portions of the Software.
15+
// *
16+
// * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
// * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
// * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
// * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
// * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
// * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
// * SOFTWARE.
23+
// *
24+
// *
25+
// * Please refer to LICENSE file.
26+
// *
27+
// ******************************************************************************
28+
// *
29+
30+
using HashifyNet.Algorithms.T1HA;
31+
using HashifyNet.UnitTests.Utilities;
32+
using Moq;
33+
34+
namespace HashifyNet.UnitTests.Algorithms.T1HA
35+
{
36+
public class T1HA0_Implementation_Tests
37+
{
38+
#region Constructor
39+
40+
#region Config
41+
42+
[Fact]
43+
public void T1HA0_Implementation_Constructor_Config_IsNull_Throws()
44+
{
45+
Assert.Equal(
46+
"config",
47+
Assert.Throws<ArgumentNullException>(
48+
() => new T1HA0_Implementation(null))
49+
.ParamName);
50+
}
51+
52+
[Fact]
53+
public void T1HA0_Implementation_Constructor_Config_IsCloned()
54+
{
55+
var tigerConfigMock = new Mock<IT1HA0Config>();
56+
{
57+
tigerConfigMock.Setup(bc => bc.Clone())
58+
.Returns(new T1HA0Config());
59+
}
60+
61+
GC.KeepAlive(
62+
new T1HA0_Implementation(tigerConfigMock.Object));
63+
64+
tigerConfigMock.Verify(bc => bc.Clone(), Times.Once);
65+
66+
tigerConfigMock.VerifyGet(bc => bc.HashSizeInBits, Times.Never);
67+
}
68+
69+
#region HashSize
70+
71+
[Fact]
72+
public void T1HA0_Implementation_Constructor_Config_HashSize_IsInvalid_Throws()
73+
{
74+
var invalidHashSizes = new[] { -1, 0, 7, 9, 10, 11, 12, 13, 14, 15, 513, 520 };
75+
76+
foreach (var invalidHashSize in invalidHashSizes)
77+
{
78+
var t1HAConfigMock = new Mock<IT1HA0Config>();
79+
{
80+
t1HAConfigMock.SetupGet(bc => bc.HashSizeInBits)
81+
.Returns(invalidHashSize);
82+
83+
t1HAConfigMock.Setup(bc => bc.Clone())
84+
.Returns(() => t1HAConfigMock.Object);
85+
}
86+
87+
Assert.Equal(
88+
"config.HashSizeInBits",
89+
Assert.Throws<ArgumentOutOfRangeException>(() =>
90+
new T1HA0_Implementation(
91+
t1HAConfigMock.Object))
92+
.ParamName);
93+
}
94+
}
95+
96+
[Fact]
97+
public void T1HA0_Implementation_Constructor_Config_ValidHashSize_Works()
98+
{
99+
var validHashSizes = new int[] { 64 };
100+
101+
foreach (var validHashSize in validHashSizes)
102+
{
103+
var t1HAConfigMock = new Mock<IT1HA0Config>();
104+
{
105+
t1HAConfigMock.SetupGet(bc => bc.HashSizeInBits)
106+
.Returns(validHashSize);
107+
108+
t1HAConfigMock.Setup(bc => bc.Clone())
109+
.Returns(() => t1HAConfigMock.Object);
110+
}
111+
112+
GC.KeepAlive(
113+
new T1HA0_Implementation(
114+
t1HAConfigMock.Object));
115+
}
116+
}
117+
118+
#endregion
119+
120+
#endregion
121+
122+
#endregion
123+
124+
#region Config
125+
126+
[Fact]
127+
public void T1HA0_Implementation_Config_IsCloneOfClone()
128+
{
129+
var t1HAConfig3 = Mock.Of<IT1HA0Config>();
130+
var t1HAConfig2 = Mock.Of<IT1HA0Config>(bc => bc.HashSizeInBits == 64 && bc.Clone() == t1HAConfig3);
131+
var t1HAConfig = Mock.Of<IT1HA0Config>(bc => bc.Clone() == t1HAConfig2);
132+
133+
var t1HAHash = new T1HA0_Implementation(t1HAConfig);
134+
135+
Assert.Equal(t1HAConfig3, t1HAHash.Config);
136+
}
137+
138+
#endregion
139+
140+
#region HashSizeInBits
141+
142+
[Fact]
143+
public void T1HA0_Implementation_HashSizeInBits_IsFromConfig()
144+
{
145+
var t1HAConfig2 = Mock.Of<IT1HA0Config>(bc => bc.HashSizeInBits == 64 && bc.Clone() == new T1HA0Config());
146+
var t1HAConfig = Mock.Of<IT1HA0Config>(bc => bc.Clone() == t1HAConfig2);
147+
148+
var tigerHash = new T1HA0_Implementation(t1HAConfig);
149+
150+
Assert.Equal(64, tigerHash.Config.HashSizeInBits);
151+
}
152+
153+
#endregion
154+
155+
public class IHashFunction_Tests_DefaultConstructor
156+
: IHashFunction_TestBase<IT1HA0, IT1HA0Config>
157+
{
158+
protected override IEnumerable<KnownValue> KnownValues { get; } =
159+
new KnownValue[] {
160+
new KnownValue(64, TestConstants.Empty, "0x0000000000000000"),
161+
new KnownValue(64, TestConstants.FooBar, "0x3147C7CE0DE73D7B"),
162+
new KnownValue(64, TestConstants.LoremIpsum, "0x5D344F1C713F8FA6"),
163+
};
164+
165+
protected override IT1HA0 CreateHashFunction(int hashSize) =>
166+
new T1HA0_Implementation(
167+
new T1HA0Config());
168+
}
169+
170+
public class IHashFunction_Tests_WithSeed
171+
: IHashFunction_TestBase<IT1HA0, IT1HA0Config>
172+
{
173+
protected override IEnumerable<KnownValue> KnownValues { get; } =
174+
new KnownValue[] {
175+
new KnownValue(64, TestConstants.Empty, "0xD6F5E2473328F26D"),
176+
new KnownValue(64, TestConstants.FooBar, "0x29C8D1B893FDCABD"),
177+
new KnownValue(64, TestConstants.LoremIpsum, "0x6F8E07013CA607BB"),
178+
};
179+
180+
protected override IT1HA0 CreateHashFunction(int hashSize) =>
181+
new T1HA0_Implementation(
182+
new T1HA0Config()
183+
{
184+
Seed = 1990L
185+
});
186+
}
187+
}
188+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// *
2+
// *****************************************************************************
3+
// *
4+
// * Copyright (c) 2025 Deskasoft International
5+
// *
6+
// * Permission is hereby granted, free of charge, to any person obtaining a copy
7+
// * of this software and associated documentation files (the "Software"), to deal
8+
// * in the Software without restriction, including without limitation the rights
9+
// * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
// * copies of the Software, and to permit persons to whom the Software is
11+
// * furnished to do so, subject to the following conditions:
12+
// *
13+
// * The above copyright notice and this permission notice shall be included in all
14+
// * copies or substantial portions of the Software.
15+
// *
16+
// * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
// * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
// * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
// * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
// * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
// * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
// * SOFTWARE.
23+
// *
24+
// *
25+
// * Please refer to LICENSE file.
26+
// *
27+
// ******************************************************************************
28+
// *
29+
30+
using HashifyNet.Algorithms.T1HA;
31+
32+
namespace HashifyNet.UnitTests.Algorithms.T1HA
33+
{
34+
public class T1HA1Config_Tests
35+
{
36+
[Fact]
37+
public void T1HA1Config_Defaults_HaventChanged()
38+
{
39+
var t1HAConfig = new T1HA1Config();
40+
Assert.Equal(64, t1HAConfig.HashSizeInBits);
41+
}
42+
43+
[Fact]
44+
public void T1HA1Config_Clone_Works()
45+
{
46+
var t1HAConfig = new T1HA1Config()
47+
{
48+
Seed = 1990L,
49+
};
50+
51+
var t1haConfigClone = t1HAConfig.Clone();
52+
53+
Assert.IsType<T1HA1Config>(t1haConfigClone);
54+
55+
Assert.Equal(t1HAConfig.HashSizeInBits, t1haConfigClone.HashSizeInBits);
56+
Assert.Equal(t1HAConfig.Seed, t1haConfigClone.Seed);
57+
}
58+
}
59+
}

0 commit comments

Comments
 (0)