def test_case1(self): result = add(1, 2) self.assertEqual(result, 3)
时间: 2024-06-04 10:12:33 浏览: 6
As an AI language model, I am unable to determine the context and purpose of this test case. However, it seems to be testing the function "add" with input values of 1 and 2 and expecting the result to be 3. The assertion method "assertEqual" is used to compare the actual result with the expected result.
相关问题
class Dog6: def __init__(self, initial_name): self._name = initial_name def get_self(self): return self def __str__(self): # # Implement this! # return __ def __repr__(self): return "<Dog named '" + self._name + "'>" def test_inside_a_method_self_refers_to_the_containing_object(self): fido = self.Dog6("Fido") self.assertEqual(__, fido.get_self()) # Not a string! def test_str_provides_a_string_version_of_the_object(self): fido = self.Dog6("Fido") self.assertEqual("Fido", str(fido)) def test_str_is_used_explicitly_in_string_interpolation(self): fido = self.Dog6("Fido") self.assertEqual(__, "My dog is " + str(fido)) def test_repr_provides_a_more_complete_string_version(self): fido = self.Dog6("Fido") self.assertEqual(__, repr(fido)) def test_all_objects_support_str_and_repr(self): seq = [1, 2, 3] self.assertEqual(__, str(seq)) self.assertEqual(__, repr(seq)) self.assertEqual(__, str("STRING")) self.assertEqual(__, repr("STRING"))
Here is the completed code with the missing parts:
```
class Dog6:
def __init__(self, initial_name):
self._name = initial_name
def get_self(self):
return self
def __str__(self):
return self._name
def __repr__(self):
return "<Dog named '" + self._name + "'>"
def test_inside_a_method_self_refers_to_the_containing_object(self):
fido = Dog6("Fido")
self.assertEqual(fido, fido.get_self()) # Not a string!
def test_str_provides_a_string_version_of_the_object(self):
fido = Dog6("Fido")
self.assertEqual("Fido", str(fido))
def test_str_is_used_explicitly_in_string_interpolation(self):
fido = Dog6("Fido")
self.assertEqual("My dog is Fido", "My dog is " + str(fido))
def test_repr_provides_a_more_complete_string_version(self):
fido = Dog6("Fido")
self.assertEqual("<Dog named 'Fido'>", repr(fido))
def test_all_objects_support_str_and_repr(self):
seq = [1, 2, 3]
self.assertEqual("[1, 2, 3]", str(seq))
self.assertEqual("[1, 2, 3]", repr(seq))
self.assertEqual("STRING", str("STRING"))
self.assertEqual("'STRING'", repr("STRING"))
```
Note that in `test_str_is_used_explicitly_in_string_interpolation`, the expected output is `"My dog is Fido"` instead of `"My dog is <Dog named 'Fido'>"` because the `+` operator implicitly calls `str` on the object being concatenated.
filename='tt11_1_1.py' from filename import earth import unittest class Test(): def test_city_country(self): earth=earth('santiago','chile') self.assertEqual(earth,'Santiago Chile') if '__name__'=='__main__': unittest.main()
这段代码有一些问题,可以修改为以下代码:
```python
from tt11_1_1 import earth
import unittest
class Test(unittest.TestCase):
def test_city_country(self):
e = earth('santiago', 'chile')
self.assertEqual(e, 'Santiago, Chile')
if __name__ == '__main__':
unittest.main()
```
在这个代码中,我们将 `tt11_1_1.py` 文件中的 `earth` 函数导入,并在测试用例中使用它。我们还将测试用例继承自 `unittest.TestCase` 类,并使用 `assertEqual` 方法来检查 `earth` 函数的输出是否与预期相同。最后,我们使用 `if __name__ == '__main__':` 来运行测试用例。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)