Skip to content

Commit

Permalink
fix: bug in how cos and sin were implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
gciatto committed May 7, 2024
1 parent c7e11cb commit d2ef2fb
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
2 changes: 2 additions & 0 deletions calculator/ui/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,10 @@ def on_button_press(self, button):
self._calc.open_parenthesis()
case "cos":
self._calc.cos()
self._calc.open_parenthesis()
case "sin":
self._calc.sin()
self._calc.open_parenthesis()
case _:
self._calc.digit(button.text)
self.display.text = self._calc.expression or "0"
Expand Down
4 changes: 2 additions & 2 deletions tests/test_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def test_expression_with_cos(self):
self.press_button(")")
self.assert_display("cos(0)")
self.press_button("=")
self.assert_display("1")
self.assert_display("1.0")

def test_expression_with_sin(self):
# sin(0) = 0
Expand All @@ -87,4 +87,4 @@ def test_expression_with_sin(self):
self.press_button(")")
self.assert_display("sin(0)")
self.press_button("=")
self.assert_display("0")
self.assert_display("0.0")
2 changes: 2 additions & 0 deletions tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def test_cosine(self):
# cos(0) = 1
self.assertEqual("", self.calculator.expression)
self.calculator.cos()
self.calculator.open_parenthesis()
self.assertEqual("cos(", self.calculator.expression)
self.calculator.digit(0)
self.calculator.close_parenthesis()
Expand All @@ -104,6 +105,7 @@ def test_sine(self):
# sin(0) = 0
self.assertEqual("", self.calculator.expression)
self.calculator.sin()
self.calculator.open_parenthesis()
self.assertEqual("sin(", self.calculator.expression)
self.calculator.digit(0)
self.calculator.close_parenthesis()
Expand Down

0 comments on commit d2ef2fb

Please sign in to comment.