【发布时间】:2022-12-02 00:40:17
【问题描述】:
Alright, so I want to reset a word after I have to change/mutated it without the reset method taking any parameters. Reset() should revert the text after the use() method is used. Is there any way of doing this?
Class words
def __init__(self, text):
self.text = text
def use(self): # sets the text as an empty string
self.text = ""
def reset(self): # revert empty string back to the original text
Here is the unit test for reset()
import unittest
from word import word
def test_reset(self):
string = word("Sunshine")
string.use()
string.reset()
self.assertEqual("Sunshine", string.text)
if __name__ == "__main__":
unittest.main()
【问题讨论】:
标签: python