55namespace Nejcc \PhpDatatypes \Tests \Integers \Signed ;
66
77use Nejcc \PhpDatatypes \Integers \Signed \Int16 ;
8- use Nejcc \PhpDatatypes \Integers \IntegerInterface ;
8+ use Nejcc \PhpDatatypes \Interfaces \IntegerInterface ;
99use PHPUnit \Framework \TestCase ;
1010
1111class Int16Test extends TestCase
1212{
13- public function testValidValueInitialization ()
13+ public function testValidInitialization ()
1414 {
1515 $ int16 = new Int16 (32767 );
1616 $ this ->assertSame (32767 , $ int16 ->getValue ());
1717 }
1818
19- public function testInvalidValueInitialization ()
19+ public function testInvalidInitialization ()
2020 {
2121 $ this ->expectException (\OutOfRangeException::class);
2222 new Int16 (32768 );
@@ -25,34 +25,104 @@ public function testInvalidValueInitialization()
2525 public function testAdditionWithinBounds ()
2626 {
2727 $ int16a = new Int16 (20000 );
28- $ int16b = new Int16 (10000 );
28+ $ int16b = new Int16 (12767 );
2929 $ int16c = $ int16a ->add ($ int16b );
30- $ this ->assertSame (30000 , $ int16c ->getValue ());
30+ $ this ->assertSame (32767 , $ int16c ->getValue ());
3131 }
3232
3333 public function testAdditionOverflow ()
3434 {
3535 $ this ->expectException (\OverflowException::class);
3636 $ int16a = new Int16 (30000 );
37- $ int16b = new Int16 (10000 );
37+ $ int16b = new Int16 (5000 );
3838 $ int16a ->add ($ int16b );
3939 }
4040
4141 public function testSubtractionWithinBounds ()
4242 {
4343 $ int16a = new Int16 (-20000 );
44- $ int16b = new Int16 (-10000 );
44+ $ int16b = new Int16 (-12767 );
4545 $ int16c = $ int16a ->subtract ($ int16b );
46- $ this ->assertSame (-10000 , $ int16c ->getValue ());
46+ $ this ->assertSame (-7233 , $ int16c ->getValue ());
4747 }
4848
4949 public function testSubtractionUnderflow ()
5050 {
5151 $ this ->expectException (\UnderflowException::class);
5252 $ int16a = new Int16 (-30000 );
53- $ int16b = new Int16 (10000 );
53+ $ int16b = new Int16 (5000 );
5454 $ int16a ->subtract ($ int16b );
5555 }
5656
57- // Add more tests for multiplication, division, modulus, equality, and comparison
57+ public function testMultiplicationWithinBounds ()
58+ {
59+ $ int16a = new Int16 (150 );
60+ $ int16b = new Int16 (200 );
61+ $ int16c = $ int16a ->multiply ($ int16b );
62+ $ this ->assertSame (30000 , $ int16c ->getValue ());
63+ }
64+
65+ public function testMultiplicationOverflow ()
66+ {
67+ $ this ->expectException (\OverflowException::class);
68+ $ int16a = new Int16 (500 );
69+ $ int16b = new Int16 (100 );
70+ $ int16a ->multiply ($ int16b );
71+ }
72+
73+ public function testDivisionWithinBounds ()
74+ {
75+ $ int16a = new Int16 (32766 );
76+ $ int16b = new Int16 (2 );
77+ $ int16c = $ int16a ->divide ($ int16b );
78+ $ this ->assertSame (16383 , $ int16c ->getValue ());
79+ }
80+
81+ public function testDivisionByZero ()
82+ {
83+ $ this ->expectException (\DivisionByZeroError::class);
84+ $ int16a = new Int16 (10000 );
85+ $ int16b = new Int16 (0 );
86+ $ int16a ->divide ($ int16b );
87+ }
88+
89+ public function testDivisionResultNotInteger ()
90+ {
91+ $ this ->expectException (\UnexpectedValueException::class);
92+ $ int16a = new Int16 (5 );
93+ $ int16b = new Int16 (2 );
94+ $ int16a ->divide ($ int16b );
95+ }
96+
97+ public function testModulusWithinBounds ()
98+ {
99+ $ int16a = new Int16 (32767 );
100+ $ int16b = new Int16 (10000 );
101+ $ int16c = $ int16a ->mod ($ int16b );
102+ $ this ->assertSame (2767 , $ int16c ->getValue ());
103+ }
104+
105+ public function testEquality ()
106+ {
107+ $ int16a = new Int16 (12345 );
108+ $ int16b = new Int16 (12345 );
109+ $ this ->assertTrue ($ int16a ->equals ($ int16b ));
110+ }
111+
112+ public function testInequality ()
113+ {
114+ $ int16a = new Int16 (12345 );
115+ $ int16b = new Int16 (30000 );
116+ $ this ->assertFalse ($ int16a ->equals ($ int16b ));
117+ }
118+
119+ public function testComparison ()
120+ {
121+ $ int16a = new Int16 (12345 );
122+ $ int16b = new Int16 (30000 ); // Valid value within range
123+ $ this ->assertSame (-1 , $ int16a ->compare ($ int16b ));
124+ $ this ->assertSame (1 , $ int16b ->compare ($ int16a ));
125+ $ int16c = new Int16 (12345 );
126+ $ this ->assertSame (0 , $ int16a ->compare ($ int16c ));
127+ }
58128}
0 commit comments