def testModAssign(self): vimcalc.parse("x = 4") vimcalc.parse("y = 5") assert vimcalc.parse("let x %= y") == "x = 4.0" vimcalc.parse("x = 4") vimcalc.parse("y = 5") assert vimcalc.parse("let y %= x") == "y = 1.0"
def testXorAssign(self): vimcalc.parse("x = 5") vimcalc.parse("y = 3") assert vimcalc.parse("let x ^= y") == "x = 6" vimcalc.parse("x = 2") vimcalc.parse("y = 10") assert vimcalc.parse("let x ^= y") == "x = 8"
def testChangeMode(self): vimcalc.parse(":dec") assert vimcalc.parse(":vars") == "VARIABLES:\n----------\n ans : 0\n e : 2.71828182846\n phi : 1.61803398875\n pi : 3.14159265359\n" vimcalc.parse(":hex") assert vimcalc.parse(":vars") == "VARIABLES:\n----------\n ans : 0x0\n e : 0x2\n phi : 0x1\n pi : 0x3\n" vimcalc.parse(":oct") assert vimcalc.parse(":vars") == "VARIABLES:\n----------\n ans : 0\n e : 02\n phi : 01\n pi : 03\n"
def testParseError(self): assert vimcalc.parse("9**5/)") == "Parse error: the expression is invalid." assert vimcalc.parse("4//5") == "Parse error: the expression is invalid." assert vimcalc.parse("--1") == "Parse error: the expression is invalid." assert vimcalc.parse("!4") == "Parse error: the expression is invalid." assert vimcalc.parse("2***3") == "Parse error: the expression is invalid." assert vimcalc.parse("sin(2,)") == "Parse error: apply() arg 2 expected sequence, found int"
def testOr(self): assert vimcalc.parse("(1|3)|9") == "ans = 11" assert vimcalc.parse("1|(3|9)") == "ans = 11" assert vimcalc.parse("1|3|9") == "ans = 11"
def testAddition(self): assert vimcalc.parse("(2+3)+4") == "ans = 9.0" assert vimcalc.parse("2+(3+4)") == "ans = 9.0" assert vimcalc.parse("2+3+4") == "ans = 9.0"
def testSubtraction(self): assert vimcalc.parse("4-3-2") == "ans = -1.0" assert vimcalc.parse("(4-3)-2") == "ans = -1.0" assert vimcalc.parse("4-(3-2)") == "ans = 3.0"
def testModulo(self): assert vimcalc.parse("(5%4)%3") == "ans = 1.0" assert vimcalc.parse("5%(4%3)") == "ans = 0.0" assert vimcalc.parse("5%4%3") == "ans = 1.0"
def testRightShift(self): assert vimcalc.parse("(16>>2)>>1") == "ans = 2" assert vimcalc.parse("16>>(2>>1)") == "ans = 8" assert vimcalc.parse("16>>1>>2") == "ans = 2"
def testComplicatedNested(self): assert vimcalc.parse("sin(sqrt(((pi/2)*2)**2)/2-(3-3))") == "ans = 1.0"
def testMultiplication(self): assert vimcalc.parse("2*2*2") == "ans = 8.0" assert vimcalc.parse("(2*2)*2") == "ans = 8.0" assert vimcalc.parse("2*(2*2)") == "ans = 8.0"
def testRightShift(self): assert vimcalc.parse("16>>1") == "ans = 8", 'right shift' assert vimcalc.parse("16>>2") == "ans = 4", 'right shift'
def testFactorial(self): assert vimcalc.parse("5!") == "ans = 120", 'factorial'
def testAddition(self): assert vimcalc.parse("5+4") == "ans = 9.0", 'addition'
def testSinh(self): assert vimcalc.parse("sinh(0)") == "ans = 0.0", 'test sinh(x)'
def testXor(self): assert vimcalc.parse("(1^3)^9") == "ans = 11" assert vimcalc.parse("1^(3^9)") == "ans = 11" assert vimcalc.parse("1^3^9") == "ans = 11"
def testUsingAssigned(self): vimcalc.parse("let a = 2") vimcalc.parse("let b = 8") vimcalc.parse("x = 2") vimcalc.parse("y = 8") assert vimcalc.parse("a + b") == "ans = 10.0", 'test using assignment' assert vimcalc.parse("x + 2") == "ans = 4.0", 'test using assignment' assert vimcalc.parse("x + y") == "ans = 10.0", 'test using assignment'
def testAssignNoLet(self): assert vimcalc.parse("x = 2") == "x = 2.0", 'test assign.' assert vimcalc.parse("x = 2.0") == "x = 2.0", 'test assign.'
def testAssign(self): assert vimcalc.parse("let x = 2") == "x = 2.0", 'test assign.' assert vimcalc.parse("let x = 2.0") == "x = 2.0", 'test assign.'
def testExponent(self): assert vimcalc.parse("(2**2)**3") == "ans = 64.0" assert vimcalc.parse("2**(2**3)") == "ans = 256.0" assert vimcalc.parse("2**2**3") == "ans = 256.0"
def testSqrt(self): assert vimcalc.parse("sqrt(64)") == "ans = 8.0", 'test sqrt(x)' assert vimcalc.parse("sqrt(0)") == "ans = 0.0", 'test sqrt(x)' assert vimcalc.parse("sqrt(2)") == "ans = 1.41421356237", 'test sqrt(x)'
def testMax(self): assert vimcalc.parse("max(3,7)") == "ans = 7.0", 'test max(x,y)' assert vimcalc.parse("max(3.2,7.6)") == "ans = 7.6", 'test max(x,y)'
def testTanh(self): assert vimcalc.parse("tanh(0)") == "ans = 0.0", 'test tanh(x)'
def testMin(self): assert vimcalc.parse("min(3,7)") == "ans = 3.0", 'test min(x,y)' assert vimcalc.parse("min(3.2,7.6)") == "ans = 3.2", 'test min(x,y)'
def runTest(self): assert vimcalc.parse("5*4") == "ans = 20.0", 'sanity check.'
def testNrt(self): assert vimcalc.parse("nrt(27,3)") == "ans = 3.0", 'test nrt(x,n)'
def testAllPrecedenceAtOnce(self): assert vimcalc.parse("5*4+2/sin(pi/2)**2+-1") == "ans = 21.0"
def testPerms(self): assert vimcalc.parse("perms(3,2)") == "ans = 6", 'test perms(n,k)'
def testDivision(self): assert vimcalc.parse("(2/2)/3") == "ans = 0.333333333333" assert vimcalc.parse("2/(2/3)") == "ans = 3.0" assert vimcalc.parse("2/2/3") == "ans = 0.333333333333"
def testPow(self): assert vimcalc.parse("pow(2,5)") == "ans = 32.0", 'test pow(x,y)'
def testLeftShift(self): assert vimcalc.parse("(8<<1)<<2") == "ans = 64" assert vimcalc.parse("8<<(1<<2)") == "ans = 128" assert vimcalc.parse("8<<1<<2") == "ans = 64"
def testRad(self): assert vimcalc.parse("rad(0)") == "ans = 0.0", 'test rad(x)' assert vimcalc.parse("rad(180)") == "ans = 3.14159265359", 'test rad(x)' assert vimcalc.parse("rad(360)") == "ans = 6.28318530718", 'test rad(x)'
def testFactorial(self): assert vimcalc.parse("5!!") == "Parse error: the expression is invalid." assert vimcalc.parse("(3!)!") == "ans = 720"
def testRound(self): assert vimcalc.parse("round(4.2)") == "ans = 4.0", 'test round(x)' assert vimcalc.parse("round(4.7)") == "ans = 5.0", 'test round(x)'
def testSin(self): assert vimcalc.parse("sin(pi/2)") == "ans = 1.0", 'test sin.' assert vimcalc.parse("sin(0)") == "ans = 0.0", 'test sin.'
def testAnd(self): assert vimcalc.parse("(1&3)&9") == "ans = 1" assert vimcalc.parse("1&(3&9)") == "ans = 1" assert vimcalc.parse("1&3&9") == "ans = 1"