5
5
namespace Nejcc \PhpDatatypes \Tests \Integers \Signed ;
6
6
7
7
use Nejcc \PhpDatatypes \Integers \Signed \Int16 ;
8
- use Nejcc \PhpDatatypes \Integers \IntegerInterface ;
8
+ use Nejcc \PhpDatatypes \Interfaces \IntegerInterface ;
9
9
use PHPUnit \Framework \TestCase ;
10
10
11
11
class Int16Test extends TestCase
12
12
{
13
- public function testValidValueInitialization ()
13
+ public function testValidInitialization ()
14
14
{
15
15
$ int16 = new Int16 (32767 );
16
16
$ this ->assertSame (32767 , $ int16 ->getValue ());
17
17
}
18
18
19
- public function testInvalidValueInitialization ()
19
+ public function testInvalidInitialization ()
20
20
{
21
21
$ this ->expectException (\OutOfRangeException::class);
22
22
new Int16 (32768 );
@@ -25,34 +25,104 @@ public function testInvalidValueInitialization()
25
25
public function testAdditionWithinBounds ()
26
26
{
27
27
$ int16a = new Int16 (20000 );
28
- $ int16b = new Int16 (10000 );
28
+ $ int16b = new Int16 (12767 );
29
29
$ int16c = $ int16a ->add ($ int16b );
30
- $ this ->assertSame (30000 , $ int16c ->getValue ());
30
+ $ this ->assertSame (32767 , $ int16c ->getValue ());
31
31
}
32
32
33
33
public function testAdditionOverflow ()
34
34
{
35
35
$ this ->expectException (\OverflowException::class);
36
36
$ int16a = new Int16 (30000 );
37
- $ int16b = new Int16 (10000 );
37
+ $ int16b = new Int16 (5000 );
38
38
$ int16a ->add ($ int16b );
39
39
}
40
40
41
41
public function testSubtractionWithinBounds ()
42
42
{
43
43
$ int16a = new Int16 (-20000 );
44
- $ int16b = new Int16 (-10000 );
44
+ $ int16b = new Int16 (-12767 );
45
45
$ int16c = $ int16a ->subtract ($ int16b );
46
- $ this ->assertSame (-10000 , $ int16c ->getValue ());
46
+ $ this ->assertSame (-7233 , $ int16c ->getValue ());
47
47
}
48
48
49
49
public function testSubtractionUnderflow ()
50
50
{
51
51
$ this ->expectException (\UnderflowException::class);
52
52
$ int16a = new Int16 (-30000 );
53
- $ int16b = new Int16 (10000 );
53
+ $ int16b = new Int16 (5000 );
54
54
$ int16a ->subtract ($ int16b );
55
55
}
56
56
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
+ }
58
128
}
0 commit comments