-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathVectorTest.php
More file actions
64 lines (50 loc) · 1.56 KB
/
Copy pathVectorTest.php
File metadata and controls
64 lines (50 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
use PHPUnit\Framework\TestCase;
use Pgvector\Vector;
final class VectorTest extends TestCase
{
public function testToString()
{
$embedding = new Vector([1, 2, 3]);
$this->assertEquals('[1,2,3]', (string) $embedding);
}
public function testToArray()
{
$embedding = new Vector([1, 2, 3]);
$this->assertEquals([1, 2, 3], $embedding->toArray());
}
public function testInvalidInteger()
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Expected array');
new Vector(1);
}
public function testInvalidArray()
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Expected array to be a list');
new Vector(['a' => 1]);
}
public function testInvalidString()
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Invalid text representation');
new Vector('{"a": 1}');
}
public function testInvalidJson()
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Invalid text representation');
new Vector("tru");
}
public function testEmptyArray()
{
$embedding = new Vector([]);
$this->assertEquals('[]', (string) $embedding);
}
public function testSplFixedArray()
{
$embedding = new Vector(SplFixedArray::fromArray([1, 2, 3]));
$this->assertEquals('[1,2,3]', (string) $embedding);
}
}