MCPcopy Index your code
hub / github.com/datacamp/pythonwhat / EqualTest

Class EqualTest

pythonwhat/Test.py:75–104  ·  view source on GitHub ↗

Check if two objects are equal. Equal means the objects are exactly the same. This test should only be used with numeric variables (for now). Attributes: feedback (str): A string containing the failure message in case the test fails. obj1 (str): The first object that sh

Source from the content-addressed store, hash-verified

73
74
75class EqualTest(Test):
76 """
77 Check if two objects are equal. Equal means the objects are exactly the same.
78 This test should only be used with numeric variables (for now).
79
80 Attributes:
81 feedback (str): A string containing the failure message in case the test fails.
82 obj1 (str): The first object that should be compared with.
83 obj2 (str): This object is compared to obj1.
84 result (bool): True if the test succeed, False if it failed. None if it hasn't been tested yet.
85 """
86
87 def __init__(self, obj1, obj2, feedback, func=None):
88 super().__init__(feedback)
89 self.obj1 = obj1
90 self.obj2 = obj2
91 self.func = func if func is not None else is_equal
92
93 def test(self):
94 """
95 Perform the actual test. result is set to False if the objects differ, True otherwise.
96 """
97 result = self.func(self.obj1, self.obj2)
98
99 try:
100 import numpy as np
101
102 self.result = np.array(result).all()
103 except ImportError:
104 self.result = result
105
106
107# Helpers for testing equality

Callers 7

has_equal_partFunction · 0.90
has_equal_astFunction · 0.90
has_exprFunction · 0.90
has_importFunction · 0.90
has_chosenFunction · 0.90
_testFunction · 0.90
callFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected