@@ -35,33 +35,79 @@ public function testInit(): AProtocol
3535 return $ protocol ;
3636 }
3737
38- // todo ..also test encode and decode in Vector class
3938 /**
4039 * @depends testInit
4140 */
4241 public function testVector (AProtocol $ protocol )
4342 {
44- $ this ->markTestIncomplete ('This test has not been implemented yet. ' );
4543 //unpack
46- // $res = iterator_to_array(
47- // $protocol
48- // ->run('RETURN ', [], ['mode' => 'r'])
49- // ->pull()
50- // ->getResponses(),
51- // false
52- // );
53- // $this->assertInstanceOf(Vector::class, $res[1]->content[0]);
44+ $ res = iterator_to_array (
45+ $ protocol
46+ ->run ('CYPHER 25 RETURN vector([1.05, 0.123, 5], 3, FLOAT),
47+ vector([1.05, 0.123, 5], 3, FLOAT32),
48+ vector([5, 543, 342765], 3, INTEGER),
49+ vector([5, -60, 120], 3, INTEGER8),
50+ vector([5, -20000, 30000], 3, INTEGER16),
51+ vector([5, -2000000000, 2000000000], 3, INTEGER32) ' ,
52+ [], ['mode ' => 'r ' ])
53+ ->pull ()
54+ ->getResponses (),
55+ false
56+ );
57+
58+ foreach ($ res [1 ]->content as $ vector ) {
59+ $ this ->assertInstanceOf (Vector::class, $ vector );
60+ }
61+
62+ // float64
63+ $ values = $ res [1 ]->content [0 ]->decode ();
64+ $ this ->assertEqualsWithDelta ([1.05 , 0.123 , 5 ], $ values , 1e-6 );
65+ // float32
66+ $ values = $ res [1 ]->content [1 ]->decode ();
67+ $ this ->assertEqualsWithDelta ([1.05 , 0.123 , 5 ], $ values , 1e-6 );
68+ // int64
69+ $ values = $ res [1 ]->content [2 ]->decode ();
70+ $ this ->assertEquals ([5 , 543 , 342765 ], $ values );
71+ // int8
72+ $ values = $ res [1 ]->content [3 ]->decode ();
73+ $ this ->assertEquals ([5 , -60 , 120 ], $ values );
74+ // int16
75+ $ values = $ res [1 ]->content [4 ]->decode ();
76+ $ this ->assertEquals ([5 , -20000 , 30000 ], $ values );
77+ // int32
78+ $ values = $ res [1 ]->content [5 ]->decode ();
79+ $ this ->assertEquals ([5 , -2000000000 , 2000000000 ], $ values );
5480
5581 //pack
56- // $res = iterator_to_array(
57- // $protocol
58- // ->run('RETURN toString($p)', [
59- // 'p' => $res[1]->content[0]
60- // ], ['mode' => 'r'])
61- // ->pull()
62- // ->getResponses(),
63- // false
64- // );
65- // $this->assertStringStartsWith('point(', $res[1]->content[0]);
82+ $ res = iterator_to_array (
83+ $ protocol
84+ ->run ('CYPHER 25 RETURN toFloatList($float), toIntegerList($int64), toIntegerList($int8), toIntegerList($int16), toIntegerList($int32) ' , [
85+ 'float ' => Vector::encode ([1.05 , 0.123 , 5.0 ]),
86+ 'int64 ' => Vector::encode ([5 , -21474836480 , 21474836470 ]),
87+ 'int8 ' => Vector::encode ([5 , -60 , 120 ]),
88+ 'int16 ' => Vector::encode ([5 , -20000 , 30000 ]),
89+ 'int32 ' => Vector::encode ([5 , -2000000000 , 2000000000 ]),
90+ ], ['mode ' => 'r ' ])
91+ ->pull ()
92+ ->getResponses (),
93+ false
94+ );
95+
96+ $ this ->assertEqualsWithDelta ([1.05 , 0.123 , 5 ], $ res [1 ]->content [0 ], 1e-6 );
97+ $ this ->assertEquals ([5 , -21474836480 , 21474836470 ], $ res [1 ]->content [1 ]);
98+ $ this ->assertEquals ([5 , -60 , 120 ], $ res [1 ]->content [2 ]);
99+ $ this ->assertEquals ([5 , -20000 , 30000 ], $ res [1 ]->content [3 ]);
100+ $ this ->assertEquals ([5 , -2000000000 , 2000000000 ], $ res [1 ]->content [4 ]);
101+ }
102+
103+ /**
104+ * @depends testInit
105+ */
106+ public function testVectorExceptions ()
107+ {
108+ $ this ->expectException (\InvalidArgumentException::class);
109+ Vector::encode ([]);
110+ $ this ->expectException (\InvalidArgumentException::class);
111+ Vector::encode (range (1 , 5000 ));
66112 }
67113}
0 commit comments