#!/usr/bin/python # # this will convert military time to common time import sys, imp, atexit sys.path.append("/home/courses/cs3214/software/pexpect-dpty/"); # sys.path.appent("~/"); import pexpect, shellio, signal, time, os, re, proc_check #Ensure the shell process is terminated def force_shell_termination(shell_process): c.close(force=True) #pulling in the regular expression and other definitions definitions_scriptname = sys.argv[1] def_module = imp.load_source('', definitions_scriptname) logfile = None if hasattr(def_module, 'logfile'): logfile = def_module.logfile # spawn an instance of the shell c = pexpect.spawn(def_module.shell, drainpty=True, logfile=logfile, args=['-p', 'plugins/']) atexit.register(force_shell_termination, shell_process=c) # set timeout for all following 'expect*' calls to 5 seconds c.timeout = 10 # test gcd c.sendline("gcd 10 30") assert c.expect_exact("The greatest common divisor is 10") == 0 c.sendline("gcd 0 30") assert c.expect_exact("The greatest common divisor is 30") == 0 c.sendline("gcd 7 30") assert c.expect_exact("The greatest common divisor is 1") == 0 c.sendline("gcd -10 30") assert c.expect_exact("The greatest common divisor is 10") == 0 #test lcm c.sendline("lcm 15 60") assert c.expect_exact("The least common multiple is 60") == 0 c.sendline("lcm -1 60") assert c.expect_exact("The least common multiple is 60") == 0 c.sendline("lcm 15 0") assert c.expect_exact("The least common multiple is 0") == 0 c.sendline("lcm 7 19") assert c.expect_exact("The least common multiple is 133") == 0 #test rprime c.sendline("rprime 13 4") assert c.expect_exact("The numbers 13 and 4 are relatively prime") == 0 c.sendline("rprime 13 26") assert c.expect_exact("The numbers 13 and 26 aren't relatively prime") == 0 c.sendline("rprime 13 -4") assert c.expect_exact("The numbers 13 and -4 are relatively prime") == 0 #test prime c.sendline("prime 13") assert c.expect_exact("The number 13 is prime") == 0 c.sendline("prime 26") assert c.expect_exact("The number 26 isn't prime") == 0 c.sendline("prime -13") assert c.expect_exact("The number -13 isn't prime") == 0 # the test was successful shellio.success()