Exemplo n.º 1
0
	def test_mod(self):
		assert isinstance(seven % 3, UserFloat)
		assert seven % 3 == UserFloat(1)
		assert seven % 3 == 1.0
		assert seven % 3 == 1
Exemplo n.º 2
0
	def test_rmod(self):
		assert isinstance(20 % seven, UserFloat)
		assert 20 % seven == UserFloat(6)
		assert 20 % seven == 6.0
		assert 20 % seven == 6
Exemplo n.º 3
0
	def test_floordiv(self):
		assert isinstance(seven // 3, UserFloat)
		assert seven // 3 == UserFloat(2)
		assert seven // 3 == 2
		assert seven // 3 == 2.0
Exemplo n.º 4
0
	def test_rfloordiv(self):
		assert isinstance(21 // seven, UserFloat)
		assert 21 // seven == UserFloat(3)
		assert 21 // seven == 3
Exemplo n.º 5
0
	def test_div(self):
		assert isinstance(seven / 3, UserFloat)
		assert seven / 3 == UserFloat(7 / 3)
		assert seven / 3 == 7 / 3
Exemplo n.º 6
0
	def test_rdiv(self):
		assert isinstance(3 / seven, UserFloat)
		assert 3 / seven == UserFloat(3 / 7)
		assert 3 / seven == UserFloat(3 / 7)
		assert 3 / seven == 3 / 7
Exemplo n.º 7
0
	def test_mul(self):
		assert isinstance(seven * 3, UserFloat)
		assert seven * 3 == UserFloat(21)
		assert seven * 3 == 21
		assert seven * 3 == 21.0
Exemplo n.º 8
0
	def test_rmul(self):
		assert isinstance(3 * seven, UserFloat)
		assert 3 * seven == UserFloat(21)
		assert 3 * seven == UserFloat(21)
		assert 3 * seven == 21
		assert 3 * seven == 21.0
Exemplo n.º 9
0
	def test_rsub(self):
		assert isinstance(3 - seven, UserFloat)
		assert 3 - seven == UserFloat(-4)
		assert 3 - seven == -UserFloat(4)
		assert 3 - seven == -4
		assert 3 - seven == -4.0
Exemplo n.º 10
0
	def test_sub(self):
		assert isinstance(seven - 3, UserFloat)
		assert seven - 3 == UserFloat(4)
		assert seven - 3 == 4
		assert seven - 3 == 4.0
Exemplo n.º 11
0
	def test_radd(self):
		assert isinstance(7 + seven, UserFloat)
		assert 7 + seven == UserFloat(14)
		assert 7 + seven == 14
		assert 7 + seven == 14.0
Exemplo n.º 12
0
	def test_add(self):
		assert isinstance(seven + 7, UserFloat)
		assert seven + 7 == UserFloat(14)
		assert seven + 7 == 14
		assert seven + 7 == 14.0
Exemplo n.º 13
0
		assert copy.copy(alice) == copy.copy(alice)

	def test_pickle(self, alice):
		assert pickle.loads(pickle.dumps(alice)) == alice  # nosec: B101

	def test_vars(self, alice):
		assert vars(alice) == dict(alice)

	def test_subclass(self):
		person = Person("Bob", 12, "Student")
		child = Child("Bob", 12, "Big School")
		assert person == child
		assert "School" not in person.__dict__


seven = UserFloat(7)


class TestUserFloat:

	def test_creation(self):
		assert isinstance(seven, Real)
		assert isinstance(seven, Number)

		assert seven == 7
		assert seven == 7.0

	def test_as_integer_ratio(self):
		assert seven.as_integer_ratio() == (7, 1)
		assert seven.as_integer_ratio() == 7.0.as_integer_ratio()