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+ }
0 commit comments