|
4 | 4 |
|
5 | 5 | namespace Nejcc\PhpDatatypes\Tests\Integers\Signed;
|
6 | 6 |
|
7 |
| -use Nejcc\PhpDatatypes\Interfaces\IntegerInterface; |
| 7 | + |
| 8 | +use Nejcc\PhpDatatypes\Scalar\Integers\Signed\Int16; |
8 | 9 | use PHPUnit\Framework\TestCase;
|
9 | 10 |
|
10 | 11 | class Int16Test extends TestCase
|
11 | 12 | {
|
12 | 13 | public function testValidInitialization()
|
13 | 14 | {
|
14 |
| - $int16 = new \Nejcc\PhpDatatypes\Scalar\Integers\Signed\Int16(32767); |
| 15 | + $int16 = new Int16(32767); |
15 | 16 | $this->assertSame(32767, $int16->getValue());
|
16 | 17 | }
|
17 | 18 |
|
18 | 19 | public function testInvalidInitialization()
|
19 | 20 | {
|
20 | 21 | $this->expectException(\OutOfRangeException::class);
|
21 |
| - new \Nejcc\PhpDatatypes\Scalar\Integers\Signed\Int16(32768); |
| 22 | + new Int16(32768); |
22 | 23 | }
|
23 | 24 |
|
24 | 25 | public function testAdditionWithinBounds()
|
25 | 26 | {
|
26 |
| - $int16a = new \Nejcc\PhpDatatypes\Scalar\Integers\Signed\Int16(20000); |
27 |
| - $int16b = new \Nejcc\PhpDatatypes\Scalar\Integers\Signed\Int16(12767); |
| 27 | + $int16a = new Int16(20000); |
| 28 | + $int16b = new Int16(12767); |
28 | 29 | $int16c = $int16a->add($int16b);
|
29 | 30 | $this->assertSame(32767, $int16c->getValue());
|
30 | 31 | }
|
31 | 32 |
|
32 | 33 | public function testAdditionOverflow()
|
33 | 34 | {
|
34 | 35 | $this->expectException(\OverflowException::class);
|
35 |
| - $int16a = new \Nejcc\PhpDatatypes\Scalar\Integers\Signed\Int16(30000); |
36 |
| - $int16b = new \Nejcc\PhpDatatypes\Scalar\Integers\Signed\Int16(5000); |
| 36 | + $int16a = new Int16(30000); |
| 37 | + $int16b = new Int16(5000); |
37 | 38 | $int16a->add($int16b);
|
38 | 39 | }
|
39 | 40 |
|
40 | 41 | public function testSubtractionWithinBounds()
|
41 | 42 | {
|
42 |
| - $int16a = new \Nejcc\PhpDatatypes\Scalar\Integers\Signed\Int16(-20000); |
43 |
| - $int16b = new \Nejcc\PhpDatatypes\Scalar\Integers\Signed\Int16(-12767); |
| 43 | + $int16a = new Int16(-20000); |
| 44 | + $int16b = new Int16(-12767); |
44 | 45 | $int16c = $int16a->subtract($int16b);
|
45 | 46 | $this->assertSame(-7233, $int16c->getValue());
|
46 | 47 | }
|
47 | 48 |
|
48 | 49 | public function testSubtractionUnderflow()
|
49 | 50 | {
|
50 | 51 | $this->expectException(\UnderflowException::class);
|
51 |
| - $int16a = new \Nejcc\PhpDatatypes\Scalar\Integers\Signed\Int16(-30000); |
52 |
| - $int16b = new \Nejcc\PhpDatatypes\Scalar\Integers\Signed\Int16(5000); |
| 52 | + $int16a = new Int16(-30000); |
| 53 | + $int16b = new Int16(5000); |
53 | 54 | $int16a->subtract($int16b);
|
54 | 55 | }
|
55 | 56 |
|
56 | 57 | public function testMultiplicationWithinBounds()
|
57 | 58 | {
|
58 |
| - $int16a = new \Nejcc\PhpDatatypes\Scalar\Integers\Signed\Int16(150); |
59 |
| - $int16b = new \Nejcc\PhpDatatypes\Scalar\Integers\Signed\Int16(200); |
| 59 | + $int16a = new Int16(150); |
| 60 | + $int16b = new Int16(200); |
60 | 61 | $int16c = $int16a->multiply($int16b);
|
61 | 62 | $this->assertSame(30000, $int16c->getValue());
|
62 | 63 | }
|
63 | 64 |
|
64 | 65 | public function testMultiplicationOverflow()
|
65 | 66 | {
|
66 | 67 | $this->expectException(\OverflowException::class);
|
67 |
| - $int16a = new \Nejcc\PhpDatatypes\Scalar\Integers\Signed\Int16(500); |
68 |
| - $int16b = new \Nejcc\PhpDatatypes\Scalar\Integers\Signed\Int16(100); |
| 68 | + $int16a = new Int16(500); |
| 69 | + $int16b = new Int16(100); |
69 | 70 | $int16a->multiply($int16b);
|
70 | 71 | }
|
71 | 72 |
|
72 | 73 | public function testDivisionWithinBounds()
|
73 | 74 | {
|
74 |
| - $int16a = new \Nejcc\PhpDatatypes\Scalar\Integers\Signed\Int16(32766); |
75 |
| - $int16b = new \Nejcc\PhpDatatypes\Scalar\Integers\Signed\Int16(2); |
| 75 | + $int16a = new Int16(32766); |
| 76 | + $int16b = new Int16(2); |
76 | 77 | $int16c = $int16a->divide($int16b);
|
77 | 78 | $this->assertSame(16383, $int16c->getValue());
|
78 | 79 | }
|
79 | 80 |
|
80 | 81 | public function testDivisionByZero()
|
81 | 82 | {
|
82 | 83 | $this->expectException(\DivisionByZeroError::class);
|
83 |
| - $int16a = new \Nejcc\PhpDatatypes\Scalar\Integers\Signed\Int16(10000); |
84 |
| - $int16b = new \Nejcc\PhpDatatypes\Scalar\Integers\Signed\Int16(0); |
| 84 | + $int16a = new Int16(10000); |
| 85 | + $int16b = new Int16(0); |
85 | 86 | $int16a->divide($int16b);
|
86 | 87 | }
|
87 | 88 |
|
88 | 89 | public function testDivisionResultNotInteger()
|
89 | 90 | {
|
90 | 91 | $this->expectException(\UnexpectedValueException::class);
|
91 |
| - $int16a = new \Nejcc\PhpDatatypes\Scalar\Integers\Signed\Int16(5); |
92 |
| - $int16b = new \Nejcc\PhpDatatypes\Scalar\Integers\Signed\Int16(2); |
| 92 | + $int16a = new Int16(5); |
| 93 | + $int16b = new Int16(2); |
93 | 94 | $int16a->divide($int16b);
|
94 | 95 | }
|
95 | 96 |
|
96 | 97 | public function testModulusWithinBounds()
|
97 | 98 | {
|
98 |
| - $int16a = new \Nejcc\PhpDatatypes\Scalar\Integers\Signed\Int16(32767); |
99 |
| - $int16b = new \Nejcc\PhpDatatypes\Scalar\Integers\Signed\Int16(10000); |
| 99 | + $int16a = new Int16(32767); |
| 100 | + $int16b = new Int16(10000); |
100 | 101 | $int16c = $int16a->mod($int16b);
|
101 | 102 | $this->assertSame(2767, $int16c->getValue());
|
102 | 103 | }
|
103 | 104 |
|
104 | 105 | public function testEquality()
|
105 | 106 | {
|
106 |
| - $int16a = new \Nejcc\PhpDatatypes\Scalar\Integers\Signed\Int16(12345); |
107 |
| - $int16b = new \Nejcc\PhpDatatypes\Scalar\Integers\Signed\Int16(12345); |
| 107 | + $int16a = new Int16(12345); |
| 108 | + $int16b = new Int16(12345); |
108 | 109 | $this->assertTrue($int16a->equals($int16b));
|
109 | 110 | }
|
110 | 111 |
|
111 | 112 | public function testInequality()
|
112 | 113 | {
|
113 |
| - $int16a = new \Nejcc\PhpDatatypes\Scalar\Integers\Signed\Int16(12345); |
114 |
| - $int16b = new \Nejcc\PhpDatatypes\Scalar\Integers\Signed\Int16(30000); |
| 114 | + $int16a = new Int16(12345); |
| 115 | + $int16b = new Int16(30000); |
115 | 116 | $this->assertFalse($int16a->equals($int16b));
|
116 | 117 | }
|
117 | 118 |
|
118 | 119 | public function testComparison()
|
119 | 120 | {
|
120 |
| - $int16a = new \Nejcc\PhpDatatypes\Scalar\Integers\Signed\Int16(12345); |
121 |
| - $int16b = new \Nejcc\PhpDatatypes\Scalar\Integers\Signed\Int16(30000); // Valid value within range |
| 121 | + $int16a = new Int16(12345); |
| 122 | + $int16b = new Int16(30000); // Valid value within range |
122 | 123 | $this->assertSame(-1, $int16a->compare($int16b));
|
123 | 124 | $this->assertSame(1, $int16b->compare($int16a));
|
124 |
| - $int16c = new \Nejcc\PhpDatatypes\Scalar\Integers\Signed\Int16(12345); |
| 125 | + $int16c = new Int16(12345); |
125 | 126 | $this->assertSame(0, $int16a->compare($int16c));
|
126 | 127 | }
|
127 | 128 | }
|
0 commit comments