Skip to content

Commit c0b9662

Browse files
Add Tensor buffer test and update license
1 parent a80df3c commit c0b9662

4 files changed

Lines changed: 41 additions & 2 deletions

File tree

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@
187187
same "printed page" as the copyright notice for easier
188188
identification within third-party archives.
189189

190-
Copyright [yyyy] [name of copyright owner]
190+
Copyright 2024 Kyrian Obikwelu
191191

192192
Licensed under the Apache License, Version 2.0 (the "License");
193193
you may not use this file except in compliance with the License.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"pestphp/pest": "^2.31",
2929
"symfony/var-dumper": "^7.0"
3030
},
31-
"license": "MIT",
31+
"license": "Apache-2.0",
3232
"autoload": {
3333
"psr-4": {
3434
"Codewithkyrian\\Transformers\\": "src/"

tests/Tensor/TensorBufferTest.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Codewithkyrian\Transformers\Tensor\Tensor;
6+
use Codewithkyrian\Transformers\Tensor\TensorBuffer;
7+
8+
beforeEach(function () {
9+
$this->tensorBuffer = new TensorBuffer(5, Tensor::float32);
10+
});
11+
12+
it('throws an exception when accessing offset with invalid type', fn() => $this->tensorBuffer['offset'])
13+
->throws(TypeError::class);
14+
15+
it('can create a zero-sized buffer', function () {
16+
$buffer = new TensorBuffer(0, Tensor::float32);
17+
18+
expect($buffer->count())->toBe(0);
19+
});
20+
21+
it('gets the correct value at the given offset using square brackets', function () {
22+
expect($this->tensorBuffer[0])->toBe(0.0)
23+
->and($this->tensorBuffer[4])->toBe(0.0);
24+
});
25+
26+
it('sets the value at the given offset using square brackets', function () {
27+
$this->tensorBuffer[0] = 1.5;
28+
$this->tensorBuffer[4] = 2.5;
29+
30+
expect($this->tensorBuffer[0])->toBe(1.5)
31+
->and($this->tensorBuffer[4])->toBe(2.5);
32+
});
33+
34+
it('throws an exception when accessing out-of-range offset', fn() => $this->tensorBuffer[5])
35+
->throws(OutOfRangeException::class);
36+
37+
it('throws an exception when unsetting offset using square brackets', function () {
38+
unset($this->tensorBuffer[0]);
39+
})->throws(LogicException::class);

0 commit comments

Comments
 (0)