Advertisement
Guest User

Untitled

a guest
Nov 25th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 3.36 KB | None | 0 0
  1. Run("calc.exe")
  2. WinWaitActive("Calculator") ; ("Калькулятор")
  3. AutoItSetOption("SendKeyDelay", 50)
  4.  
  5. TestOperations()
  6.  
  7. MsgBox(0, "Test Finished", "Test is finished")
  8.  
  9. Exit
  10.  
  11. Func TestOperations()
  12.   TestAddition()
  13.   TestSubtraction()
  14.   TestMultiplication()
  15.   TestDivision()
  16.   TestRev()
  17.   TestSqrt()
  18.   TestExtraButtons()
  19.   TestBackspace()
  20.   TestPercentage()
  21. EndFunc
  22.  
  23. Func TestAddition()
  24.   Send("{ESC}{ESC}")
  25.   Send("1023456789")
  26.   Send("{+}")
  27.   Send("9087654321")
  28.   Send("{ENTER}")
  29.   AssertEq(GetResult(), 10111111110, "TestAddition")
  30.   Send("{ESC}{ESC}")
  31.   Send("100,5")
  32.   Send("{+}")
  33.   Send("100,2")
  34.   Send("{ENTER}")
  35.   AssertEq(GetResult(), 200.7, "TestAddition")
  36.   Send("{ESC}{ESC}")
  37.   Send("-100,5")
  38.   Send("{+}")
  39.   Send("100,2")
  40.   Send("{ENTER}")
  41.   AssertEq(GetResult(), -0.3, "TestAddition")
  42. EndFunc
  43.  
  44. Func TestSubtraction()
  45.   Send("{ESC}{ESC}")
  46.   Send("1200")
  47.   Send("{-}")
  48.   Send("200")
  49.   Send("{ENTER}")
  50.   AssertEq(GetResult(), 1000, "TestSubtraction")
  51.   Send("{ESC}{ESC}")
  52.   Send("200")
  53.   Send("{-}")
  54.   Send("1200")
  55.   Send("{ENTER}")
  56.   AssertEq(GetResult(), -1000, "TestSubtraction")
  57.   Send("{ESC}{ESC}")
  58.   Send("200,1")
  59.   Send("{-}")
  60.   Send("1200")
  61.   Send("{ENTER}")
  62.   AssertEq(GetResult(), -999.9, "TestSubtraction")
  63. EndFunc
  64.  
  65. Func TestMultiplication()
  66.   Send("{ESC}{ESC}")
  67.   Send("10")
  68.   Send("{*}")
  69.   Send("20")
  70.   Send("{ENTER}")
  71.   AssertEq(GetResult(), 200, "TestMultiplication")
  72.   Send("{ESC}{ESC}")
  73.   Send("10,2")
  74.   Send("{*}")
  75.   Send("-4")
  76.   Send("{ENTER}")
  77.   AssertEq(GetResult(), -40.8, "TestMultiplication")
  78. EndFunc
  79.  
  80.  
  81. Func TestDivision()
  82.   Send("{ESC}{ESC}")
  83.   Send("-10")
  84.   Send("{/}")
  85.   Send("20")
  86.   Send("{ENTER}")
  87.   AssertEq(GetResult(), -0.5, "TestDivision")
  88.   Send("{ESC}{ESC}")
  89.   Send("100")
  90.   Send("{/}")
  91.   Send("5")
  92.   Send("{ENTER}")
  93.   AssertEq(GetResult(), 20, "TestDivision")
  94.   Send("{ESC}{ESC}")
  95.   Send("0,02")
  96.   Send("{/}")
  97.   Send("2")
  98.   Send("{ENTER}")
  99.   AssertEq(GetResult(), 0.01, "TestDivision")
  100. EndFunc
  101.  
  102.  
  103. Func TestRev()
  104.   Send("{ESC}{ESC}")
  105.   Send("8")
  106.   Send("{r}")
  107.   AssertEq(GetResult(), 0.125, "TestReverse")
  108. EndFunc
  109.  
  110. Func TestSqrt()
  111.   Send("{ESC}{ESC}")
  112.   Send("8")
  113.   Send("{@}")
  114.   AssertEq(GetResult(), 64, "TestReverse")
  115. EndFunc
  116.  
  117.  
  118. Func TestExtraButtons()
  119.   Send("{ESC}{ESC}")
  120.   Send("8")
  121.   Send("{CTRL}M")
  122.   Send("{ESC}{ESC}")
  123.   Send("{CTRL}R")
  124.   AssertEq(GetResult(), 8, "Test MS and MR")
  125.   Send("{CTRL}L")
  126.   Send("{CTRL}R")
  127.   AssertEq(GetResult(), 0, "Test MC")
  128.   Send("8")
  129.   Send("{CTRL}M")
  130.   Send("8")
  131.   Send("{CTRL}P")
  132.   Send("{CTRL}R")
  133.   AssertEq(GetResult(), 16, "Test M+")
  134. EndFunc
  135.  
  136. Func TestBackspace()
  137.   Send("82")
  138.   Send("{BACKSPACE}")
  139.   AssertEq(GetResult(), 8, "TestBackspace")
  140. EndFunc
  141.  
  142. Func TestPercentage()
  143. Send("{ESC}{ESC}")
  144. Send("100")
  145. Send("{*}")
  146. Send("15%")
  147. AssertEq(GetResult(), 15, "TestPercentageMultiplication")
  148. Send("{ESC}{ESC}")
  149. Send("100")
  150. Send("{+}")
  151. Send("15%")
  152. Send("{ENTER}")
  153. AssertEq(GetResult(), 115, "TestPercentageAddition")
  154. Send("{ESC}{ESC}")
  155. Send("100")
  156. Send("{-}")
  157. Send("15%")
  158. Send("{ENTER}")
  159. AssertEq(GetResult(), 85, "TestPercentageSubtraction")
  160. EndFunc
  161.  
  162.  
  163. Func GetResult()
  164.     Send("^c")
  165.     $str = StringReplace(ClipGet(), ",", ".")
  166.     return Number($str)
  167.  EndFunc
  168.  
  169. Func AssertEq($Result, $Expect, $Message)
  170.     If $Result <> $Expect Then
  171.     MsgBox(0, $Message, "Test is failed")
  172.     EndIf
  173. EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement