示例#1
0
 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"
示例#2
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"
示例#3
0
 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"
示例#4
0
 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"
示例#5
0
文件: tests.py 项目: mMontu/VimCalc
 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"
示例#6
0
 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"
示例#7
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"
示例#8
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"
示例#9
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"
示例#10
0
 def testComplicatedNested(self):
     assert vimcalc.parse("sin(sqrt(((pi/2)*2)**2)/2-(3-3))") == "ans = 1.0"
示例#11
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"
示例#12
0
 def testRightShift(self):
     assert vimcalc.parse("16>>1") == "ans = 8", 'right shift'
     assert vimcalc.parse("16>>2") == "ans = 4", 'right shift'
示例#13
0
 def testFactorial(self):
     assert vimcalc.parse("5!") == "ans = 120", 'factorial'
示例#14
0
文件: tests.py 项目: mMontu/VimCalc
 def testAddition(self):
     assert vimcalc.parse("5+4") == "ans = 9.0", 'addition'
示例#15
0
 def testSinh(self):
     assert vimcalc.parse("sinh(0)")       == "ans = 0.0", 'test sinh(x)'
示例#16
0
文件: tests.py 项目: mMontu/VimCalc
 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"
示例#17
0
文件: tests.py 项目: mMontu/VimCalc
 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'
示例#18
0
文件: tests.py 项目: mMontu/VimCalc
 def testAssignNoLet(self):
     assert vimcalc.parse("x = 2") == "x = 2.0", 'test assign.'
     assert vimcalc.parse("x = 2.0") == "x = 2.0", 'test assign.'
示例#19
0
文件: tests.py 项目: mMontu/VimCalc
 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.'
示例#20
0
文件: tests.py 项目: mMontu/VimCalc
 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"
示例#21
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)'
示例#22
0
 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)'
示例#23
0
 def testTanh(self):
     assert vimcalc.parse("tanh(0)")       == "ans = 0.0", 'test tanh(x)'
示例#24
0
 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)'
示例#25
0
 def runTest(self):
     assert vimcalc.parse("5*4") == "ans = 20.0", 'sanity check.'
示例#26
0
 def testNrt(self):
     assert vimcalc.parse("nrt(27,3)")     == "ans = 3.0", 'test nrt(x,n)'
示例#27
0
 def testAllPrecedenceAtOnce(self):
     assert vimcalc.parse("5*4+2/sin(pi/2)**2+-1") == "ans = 21.0"
示例#28
0
 def testPerms(self):
     assert vimcalc.parse("perms(3,2)")    == "ans = 6", 'test perms(n,k)'
示例#29
0
 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"
示例#30
0
 def testPow(self):
     assert vimcalc.parse("pow(2,5)")      == "ans = 32.0", 'test pow(x,y)'
示例#31
0
 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"
示例#32
0
 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)'
示例#33
0
 def testFactorial(self):
     assert vimcalc.parse("5!!")   == "Parse error: the expression is invalid."
     assert vimcalc.parse("(3!)!") == "ans = 720"
示例#34
0
 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)'
示例#35
0
 def testAddition(self):
     assert vimcalc.parse("5+4") == "ans = 9.0", 'addition'
示例#36
0
 def testSin(self):
     assert vimcalc.parse("sin(pi/2)")     == "ans = 1.0", 'test sin.'
     assert vimcalc.parse("sin(0)")        == "ans = 0.0", 'test sin.'
示例#37
0
 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"
示例#38
0
文件: tests.py 项目: mMontu/VimCalc
 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"