[dead]
ME:
def (x: int):
for i in range(x):
print(i)
It takes an int. Are you trolling now or did you get mixed up with something else? #unit testable code (without using dependency injection tricks)
def cool_function(x: int) -> None:
IO_function(logic_function(x))
def logic_function(x: int) -> List[int]:
return [i for i in range(x)]
def IO_function(x: Any) -> None:
print(x)
def test_output():
assert logic_function(4) == [i for i in range(4)]
Chatgpt only gave you logic_function, because IO_function is sort of obvious.. it's just "print" (I only wrapped print in "IO_function" to keep things clear, typically you won't define that function). But basically the full complete code would be to recompose IO with logic. You now have two components one of which is testable. (Btw making print formatting unit testable means segregating the formatting from the print. Produce the string first, test that, then print, because print can never be unit tested by definition)
Right? Think about it. You want to unit test your formatting, remove the logic from the atomic IO function. Otherwise you can't test it via a unit test because that's the definition of unit testing. I realize that there is formatting that's part of the internal functionality of printf, but really all that means is that funcitonality can never really be unit tested. If you want to test printf, that happens at the integration level... By Defintion.