Last active
July 26, 2018 22:31
-
-
Save wrenoud/6be6f7509c88a3d8f9867ae782fb768f to your computer and use it in GitHub Desktop.
Rockstar Math Module (https://github.com/dylanbeattie/rockstar), transpiled to python with https://github.com/yanorestes/rockstar-py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The loneliest is a. | |
(Abs function) | |
(returns the absolute value of 'a thought') | |
Abs takes a thought | |
If a thought is greater than nothing | |
Give back a thought | |
Else | |
Give back nothing without a thought | |
(end Abs function) | |
(Pow function) | |
(returns 'all' raised to 'your base') | |
Pow takes all and your base | |
If your base is empty | |
Give back the loneliest | |
(end if) | |
If your base is less than nothing | |
Put nothing without your base into your base | |
Give back the loneliest over Pow taking all, your base | |
(end if) | |
Put the loneliest into the one | |
Put all into the magic | |
While the one is smaller than your base | |
Put all of the magic into the magic | |
Build the one up | |
(end while) | |
Give back the magic | |
(end Pow function) | |
(some constants for Sqrt function) | |
The wing is strange. | |
My song is knickknack. lumberjacks | |
Put Pow taking my song, the wing into the dawn | |
Half is flummoxing. huzza | |
(Sqrt function) | |
(iterates until the estimate update is less than 'the dawn') | |
Sqrt takes a mountain | |
If a mountain is nowhere | |
Give back nothing | |
(end if) | |
Put a mountain into a molehill | |
Put a molehill into the sea | |
While Abs taking the sea is greater than the dawn | |
Put a molehill into the sea | |
Put Half of a molehill with Half of a mountain over a molehill into a molehill | |
Put the sea without a molehill into the sea | |
(end while) | |
Give back a molehill | |
(end Sqrt function) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
the_loneliest = 1 | |
#Abs function | |
#returns the absolute value of 'a thought' | |
def Abs(a_thought): | |
if a_thought > False: | |
return a_thought | |
else: | |
return False - a_thought | |
#end Abs function | |
#Pow function | |
#returns 'all' raised to 'your base' | |
def Pow(all, your_base): | |
if your_base == False: | |
return the_loneliest | |
#end if | |
if your_base < False: | |
your_base = False - your_base | |
return the_loneliest / Pow(all, your_base) | |
#end if | |
the_one = the_loneliest | |
the_magic = all | |
while the_one < your_base: | |
the_magic = all * the_magic | |
the_one += 1 | |
#end while | |
return the_magic | |
#end Pow function | |
#some constants for Sqrt function | |
the_wing = 7 | |
my_song = 0.1 | |
the_dawn = Pow(my_song, the_wing) | |
Half = 0.5 | |
#Sqrt function | |
#iterates until the estimate update is less than 'the dawn' | |
def Sqrt(a_mountain): | |
if a_mountain == False: | |
return False | |
#end if | |
a_molehill = a_mountain | |
the_sea = a_molehill | |
while Abs(the_sea) > the_dawn: | |
the_sea = a_molehill | |
a_molehill = Half * a_molehill + Half * a_mountain / a_molehill | |
the_sea = the_sea - a_molehill | |
#end while | |
return a_molehill | |
#end Sqrt function |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
import unittest | |
from math_rock import Abs, Pow, Sqrt | |
class TestMathAbs(unittest.TestCase): | |
def testAbsPositive(self): | |
self.assertEqual(Abs(100.5), 100.5) | |
def testAbsNegative(self): | |
self.assertEqual(Abs(-100.5), 100.5) | |
def testAbsZero(self): | |
self.assertEqual(Abs(0.0), 0.0) | |
class TestMathPow(unittest.TestCase): | |
def testPowPositive(self): | |
self.assertEqual(Pow(3,6), math.pow(3,6)) | |
def testPowZero(self): | |
self.assertEqual(Pow(3,0), math.pow(3,0)) | |
def testPowNegative(self): | |
self.assertEqual(Pow(3,-1), math.pow(3,-1)) | |
class TestMathSqrt(unittest.TestCase): | |
def testSqrtPositive(self): | |
self.assertEqual(Sqrt(28), math.sqrt(28)) | |
def testSqrtZero(self): | |
self.assertEqual(Sqrt(0), math.sqrt(0)) | |
def testSqrtNegative(self): | |
with self.assertRaises(ZeroDivisionError): | |
Sqrt(-1) | |
if __name__ == '__main__': | |
unittest.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment