|
1 | 1 | <?php |
2 | 2 |
|
3 | | -use Nejcc\PhpDatatypes\Integers\Signed\Int16; |
4 | | -use Nejcc\PhpDatatypes\Integers\Signed\Int32; |
5 | | -use Nejcc\PhpDatatypes\Integers\Signed\Int8; |
6 | | -use Nejcc\PhpDatatypes\Integers\Unsigned\UInt8; |
| 3 | +use Nejcc\PhpDatatypes\Composite\Arrays\ByteSlice; |
| 4 | +use Nejcc\PhpDatatypes\Composite\Arrays\FloatArray; |
| 5 | +use Nejcc\PhpDatatypes\Composite\Arrays\IntArray; |
| 6 | +use Nejcc\PhpDatatypes\Composite\Arrays\StringArray; |
| 7 | +use Nejcc\PhpDatatypes\Scalar\Byte; |
| 8 | +use Nejcc\PhpDatatypes\Scalar\FloatingPoints\Float32; |
| 9 | +use Nejcc\PhpDatatypes\Scalar\FloatingPoints\Float64; |
| 10 | +use Nejcc\PhpDatatypes\Scalar\Char; |
| 11 | +use Nejcc\PhpDatatypes\Scalar\Integers\Signed\Int16; |
| 12 | +use Nejcc\PhpDatatypes\Scalar\Integers\Signed\Int8; |
| 13 | +use Nejcc\PhpDatatypes\Scalar\Integers\Unsigned\UInt32; |
7 | 14 |
|
8 | 15 | require_once __DIR__ . '/vendor/autoload.php'; |
9 | 16 |
|
10 | | -class test |
| 17 | +class TestExamples |
11 | 18 | { |
12 | | - public \Nejcc\PhpDatatypes\Floats\Float8 $min; |
| 19 | + private Float32 $account_balance; |
| 20 | + private Float64 $investment_amount; |
| 21 | + private Char $grade; |
| 22 | + private Byte $age; |
| 23 | + private StringArray $names; |
| 24 | + private IntArray $scores; |
| 25 | + private FloatArray $weights; |
| 26 | + private ByteSlice $data; |
| 27 | + private Int8 $years; |
| 28 | + private UInt32 $account_number; |
13 | 29 |
|
14 | | - public function __construct(int $int) |
| 30 | + public function __construct() |
15 | 31 | { |
16 | | - $this->min = float8($int); |
| 32 | + $this->years = int8(33); |
| 33 | + $this->account_number = uint32(343233); |
| 34 | + // Scalar Types |
| 35 | + $this->account_balance = float32(1234.56); |
| 36 | + $this->investment_amount = float64(78910.12345); |
| 37 | + $this->grade = new Char('A'); |
| 38 | + $this->age = new Byte(25); |
| 39 | + |
| 40 | + // Composite Types (Arrays) |
| 41 | + $this->names = new StringArray(['John', 'Jane', 'Doe']); |
| 42 | + $this->scores = new IntArray([100, 95, 87]); |
| 43 | + $this->weights = new FloatArray([60.5, 72.3, 88.9]); |
| 44 | + $this->data = new ByteSlice([255, 128, 0]); |
| 45 | + |
17 | 46 | } |
18 | 47 |
|
19 | | - public function __invoke(): \Nejcc\PhpDatatypes\Floats\Float8 |
| 48 | + public function getExamples(): array |
20 | 49 | { |
21 | | - return $this->min; |
| 50 | + /* |
| 51 | + * Test only |
| 52 | + array (size=10) |
| 53 | + 'years' => |
| 54 | + object(Nejcc\PhpDatatypes\Scalar\Integers\Signed\Int8)[4] |
| 55 | + protected readonly int 'value' => int 33 |
| 56 | + 'account_number' => |
| 57 | + object(Nejcc\PhpDatatypes\Scalar\Integers\Unsigned\UInt32)[5] |
| 58 | + protected readonly int 'value' => int 343233 |
| 59 | + 'account_balance' => |
| 60 | + object(Nejcc\PhpDatatypes\Scalar\FloatingPoints\Float32)[6] |
| 61 | + protected readonly float 'value' => float 1234.56 |
| 62 | + 'investment_amount' => |
| 63 | + object(Nejcc\PhpDatatypes\Scalar\FloatingPoints\Float64)[7] |
| 64 | + protected readonly float 'value' => float 78910.12345 |
| 65 | + 'grade' => |
| 66 | + object(Nejcc\PhpDatatypes\Scalar\Char)[8] |
| 67 | + private string 'value' => string 'A' (length=1) |
| 68 | + 'age' => |
| 69 | + object(Nejcc\PhpDatatypes\Scalar\Byte)[9] |
| 70 | + private int 'value' => int 25 |
| 71 | + 'names' => |
| 72 | + object(Nejcc\PhpDatatypes\Composite\Arrays\StringArray)[10] |
| 73 | + private array 'value' => |
| 74 | + array (size=3) |
| 75 | + 0 => string 'John' (length=4) |
| 76 | + 1 => string 'Jane' (length=4) |
| 77 | + 2 => string 'Doe' (length=3) |
| 78 | + 'scores' => |
| 79 | + object(Nejcc\PhpDatatypes\Composite\Arrays\IntArray)[11] |
| 80 | + private array 'value' => |
| 81 | + array (size=3) |
| 82 | + 0 => int 100 |
| 83 | + 1 => int 95 |
| 84 | + 2 => int 87 |
| 85 | + 'weights' => |
| 86 | + object(Nejcc\PhpDatatypes\Composite\Arrays\FloatArray)[12] |
| 87 | + private array 'value' => |
| 88 | + array (size=3) |
| 89 | + 0 => float 60.5 |
| 90 | + 1 => float 72.3 |
| 91 | + 2 => float 88.9 |
| 92 | + 'data' => |
| 93 | + object(Nejcc\PhpDatatypes\Composite\Arrays\ByteSlice)[13] |
| 94 | + private array 'value' => |
| 95 | + array (size=3) |
| 96 | + 0 => int 255 |
| 97 | + 1 => int 128 |
| 98 | + 2 => int 0 |
| 99 | + */ |
| 100 | + return [ |
| 101 | + 'years' => $this->years, |
| 102 | + 'account_number' => $this->account_number, |
| 103 | + 'account_balance' => $this->account_balance, |
| 104 | + 'investment_amount' => $this->investment_amount, |
| 105 | + 'grade' => $this->grade, |
| 106 | + 'age' => $this->age, |
| 107 | + 'names' => $this->names, |
| 108 | + 'scores' => $this->scores, |
| 109 | + 'weights' => $this->weights, |
| 110 | + 'data' => $this->data, |
| 111 | + ]; |
22 | 112 | } |
23 | 113 | } |
24 | 114 |
|
25 | | -$c = new test(8); |
26 | | -var_dump($c); |
27 | | - |
28 | | - |
| 115 | +// Instantiate the class and invoke the examples |
| 116 | +$example = new TestExamples(); |
| 117 | +var_dump($example->getExamples()); |
0 commit comments