def test_new_from_value(): s = Scalar.new_from_value(False) assert s.dtype == bool assert s.value == False s2 = Scalar.new_from_value(-1.1) assert s2.dtype == 'FP64' assert s2.value == -1.1
def test_new_from_type(): s = Scalar.new_from_type(dtypes.INT8) assert s.dtype == 'INT8' assert s.value == 0 # must hold a value; initialized to 0 s2 = Scalar.new_from_type(bool) assert s2.dtype == 'BOOL' assert s2.value == False # must hold a value; initialized to False
def test_truthy(s): assert s, 's did not register as truthy' with pytest.raises(AssertionError): assert not s s2 = Scalar.new_from_value(True) assert s2 with pytest.raises(AssertionError): assert not s2
def test_clear(s): assert s.value == 5 s.clear() assert s.value == 0 # must hold a value; reset to 0 s2 = Scalar.new_from_value(True) assert s2.value == True s2.clear() assert s2.value == False # must hold a value; reset to False
def test_assign_scalar(v): result = Vector.new_from_values([1, 3, 4, 5, 6], [9, 9, 2, 9, 0]) w = Vector.new_from_existing(v) w.assign[[1, 3, 5]] = 9 assert w == result w = Vector.new_from_existing(v) w.assign[1::2] = 9 assert w == result w = Vector.new_from_values([0, 1, 2], [1, 1, 1]) s = Scalar.new_from_value(9) w.assign[:] = s assert w == Vector.new_from_values([0, 1, 2], [9, 9, 9])
def s(): return Scalar.new_from_value(5)
def test_new_from_existing(s): s2 = Scalar.new_from_existing(s) assert s2.dtype == s.dtype assert s2.value == s.value