Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STCC-319 Convert Exponent Function #234

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/scratchtocatrobat/converter/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ class _ScratchToCatrobat(object):
"10 ^": lambda value: catrobat.create_formula_element_for([catformula.Functions.POWER, 10, value]),
"floor": catformula.Functions.FLOOR,
"ceiling": catformula.Functions.CEIL,
"e ^": catformula.Functions.EXP
}

math_unary_operators_mapping = {
Expand Down
16 changes: 16 additions & 0 deletions src/scratchtocatrobat/converter/test_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,22 @@ def test_can_convert_pow_of_10_block(self):
self.assertIsNone(exponent_fe.leftChild)
self.assertIsNone(exponent_fe.rightChild)

# e ^
def test_can_convert_exponent_block(self):
exponent = 6
scratch_block = ["e ^", exponent]
[formula_element] = self.block_converter._catrobat_bricks_from(scratch_block, DUMMY_CATR_SPRITE)
self.assertIsInstance(formula_element, catformula.FormulaElement)
self.assertEqual(formula_element.type, catformula.FormulaElement.ElementType.FUNCTION)
self.assertEqual(formula_element.value, catformula.Functions.EXP.toString())

exponent_fe = formula_element.leftChild
self.assertIsInstance(exponent_fe, catformula.FormulaElement)
self.assertEqual(exponent_fe.type, catformula.FormulaElement.ElementType.NUMBER)
self.assertEqual(exponent_fe.value, "6")
self.assertIsNone(exponent_fe.leftChild)
self.assertIsNone(exponent_fe.rightChild)

# lineCountOfList:
def test_can_convert_line_count_of_list_block(self):
scratch_block = ["lineCountOfList:", self._name_of_test_list]
Expand Down