@@ -809,6 +809,64 @@ def test_vector(self):
809
809
dtype = BinaryVectorDtype .PACKED_BIT ,
810
810
) # type: ignore[call-overload]
811
811
812
+ def assertRepr (self , obj ):
813
+ new_obj = eval (repr (obj ))
814
+ self .assertEqual (type (new_obj ), type (obj ))
815
+ self .assertEqual (repr (new_obj ), repr (obj ))
816
+
817
+ def test_binaryvector_repr (self ):
818
+ """Tests of repr(BinaryVector)"""
819
+
820
+ data = [1 / 127 , - 7 / 6 ]
821
+ one = BinaryVector (data , BinaryVectorDtype .FLOAT32 )
822
+ self .assertEqual (
823
+ repr (one ), f"BinaryVector(dtype=BinaryVectorDtype.FLOAT32, padding=0, data={ data } )"
824
+ )
825
+ self .assertRepr (one )
826
+
827
+ data = [127 , 7 ]
828
+ two = BinaryVector (data , BinaryVectorDtype .INT8 )
829
+ self .assertEqual (
830
+ repr (two ), f"BinaryVector(dtype=BinaryVectorDtype.INT8, padding=0, data={ data } )"
831
+ )
832
+ self .assertRepr (two )
833
+
834
+ three = BinaryVector (data , BinaryVectorDtype .INT8 , padding = 0 )
835
+ self .assertEqual (
836
+ repr (three ), f"BinaryVector(dtype=BinaryVectorDtype.INT8, padding=0, data={ data } )"
837
+ )
838
+ self .assertRepr (three )
839
+
840
+ four = BinaryVector (data , BinaryVectorDtype .PACKED_BIT , padding = 3 )
841
+ self .assertEqual (
842
+ repr (four ), f"BinaryVector(dtype=BinaryVectorDtype.PACKED_BIT, padding=3, data={ data } )"
843
+ )
844
+ self .assertRepr (four )
845
+
846
+ zero = BinaryVector ([], BinaryVectorDtype .INT8 )
847
+ self .assertEqual (
848
+ repr (zero ), "BinaryVector(dtype=BinaryVectorDtype.INT8, padding=0, data=[])"
849
+ )
850
+ self .assertRepr (zero )
851
+
852
+ def test_binaryvector_equality (self ):
853
+ """Tests of == __eq__"""
854
+ self .assertEqual (
855
+ BinaryVector ([1.2 , 1 - 1 / 3 ], BinaryVectorDtype .FLOAT32 , 0 ),
856
+ BinaryVector ([1.2 , 1 - 1.0 / 3.0 ], BinaryVectorDtype .FLOAT32 , 0 ),
857
+ )
858
+ self .assertNotEqual (
859
+ BinaryVector ([1.2 , 1 - 1 / 3 ], BinaryVectorDtype .FLOAT32 , 0 ),
860
+ BinaryVector ([1.2 , 6.0 / 9.0 ], BinaryVectorDtype .FLOAT32 , 0 ),
861
+ )
862
+ self .assertEqual (
863
+ BinaryVector ([], BinaryVectorDtype .FLOAT32 , 0 ),
864
+ BinaryVector ([], BinaryVectorDtype .FLOAT32 , 0 ),
865
+ )
866
+ self .assertNotEqual (
867
+ BinaryVector ([1 ], BinaryVectorDtype .INT8 ), BinaryVector ([2 ], BinaryVectorDtype .INT8 )
868
+ )
869
+
812
870
def test_unicode_regex (self ):
813
871
"""Tests we do not get a segfault for C extension on unicode RegExs.
814
872
This had been happening.
0 commit comments