def test_matrix(): output = matrix([[1, 2, 3, 4, 5], [2, 3, 4, 5, 6], [3, 5, 7, 9, 11], [5, 13, 29, 61, 125] # , # [13, 65533, 2**65536-3, 2**2**65536-3, 2**2**2**65536-3] ]) for m in range(3): for n in range(4): assert ack(m, n) == output[m, n]
def test_matrix(): output = matrix([ [1, 2, 3, 4, 5], [2, 3, 4, 5, 6], [3, 5, 7, 9, 11], [5, 13, 29, 61, 125] # , # [13, 65533, 2**65536-3, 2**2**65536-3, 2**2**2**65536-3] ]) for m in range(3): for n in range(4): assert ack(m, n) == output[m, n]
def __init__(self, thisdirective): self.ID = None # each directive has a unique ID self.lastfailtime = None # last time a failure was detected self.faildetecttime = None # first time failure was detected for current problem self.ack = ack.ack() # ack object to track acknowledgements self.checkcount = 0 # count number of checks/re-checks self.failcount = 0 # count number of continuous failed checks self.thisdirective = thisdirective # pointer to the directive this object belongs to # status holds the status of the most recent check. # Values can be: # ok - no problem # failinitial - possible failure state (might need more rechecks, for example) # fail - check has failed # unknown - not executed yet # Initial value cannot be 'ok' because of 'checkdependson' race-condition. self.status = 'unknown' # Status of most recent check.
def __init__(self, toklist): # Check toklist for valid tokens if len(toklist) < 2: # need at least 2 tokens raise ParseFailure, "Directive expected at least 3 tokens, found %d" % len(toklist) if toklist[-1] != ':': # last token should be a ':' raise ParseFailure, "Directive expected ':' but didn't find one" self.basetype = 'Directive' # the object can know its own basetype self.type = toklist[0] # the directive type of this instance self.Action = action.action() # create new action instance self.Action.varDict = {} # dictionary of variables used for emails etc self.actionList = [] # each directive will have a list of actions # Set up informational variables - these are common to all Directives # %h = hostname self.Action.varDict['h'] = log.hostname # %sys = command from a system() action # TODO self.Action.varDict['sys'] = '[sys not yet defined]' # %act = show list of actions taken preceded by "The following actions # were taken:" if any were taken self.Action.varDict['act'] = '[act not yet defined]' # %actnm = show list of actions taken (excluding email()'s) preceded by # "The following actions were taken:" if any were taken self.Action.varDict['actnm'] = '[actnm not yet defined]' # each directive has a unique ID self.ID = None # directives keep state information about themselves self.lastfailtime = None # last time a failure was detected self.faildetecttime = None # first time failure was detected for current problem self.ack = ack.ack() # ack object to track acknowledgements self.status = "ok" # status of most recent check: "ok" or "fail"
def test_expected(): u"""Assert that ack() reutrns expected values.""" for input_ in vals: assert ack.ack(input_[0], input_[1]) == vals[input_]
def test_neg2(): assert ack(2, -1) is None
def test_neg(): assert ack(-1, 0) is None
def test_ack(): assert ack(0,0) == 1 assert ack(0,1) == 2 assert ack(1,0) == 2 assert ack(1,1) == 3 assert ack(0,2) == 3 assert ack(0,3) == 4 assert ack(0,4) == 5 assert ack(1,2) == 4 assert ack(1,3) == 5 assert ack(1,4) == 6 assert ack(2,0) == 3 assert ack(2,1) == 5 assert ack(2,2) == 7 assert ack(2,3) == 9 assert ack(2,4) == 11 assert ack(3,0) == 5 assert ack(3,1) == 13 assert ack(3,2) == 29 assert ack(3,3) == 61 assert ack(3,4) == 125
def test_ack(): assert ack(0, 0) == 1 assert ack(0, 1) == 2 assert ack(1, 0) == 2 assert ack(1, 1) == 3 assert ack(0, 2) == 3 assert ack(0, 3) == 4 assert ack(0, 4) == 5 assert ack(1, 2) == 4 assert ack(1, 3) == 5 assert ack(1, 4) == 6 assert ack(2, 0) == 3 assert ack(2, 1) == 5 assert ack(2, 2) == 7 assert ack(2, 3) == 9 assert ack(2, 4) == 11 assert ack(3, 0) == 5 assert ack(3, 1) == 13 assert ack(3, 2) == 29 assert ack(3, 3) == 61 assert ack(3, 4) == 125
from ack import ack count1 = 0 if ack(0, 0) == 1: count1 = count1 + 1 if ack(1, 0) == 2: count1 = count1 + 1 if ack(2, 0) == 3: count1 = count1 + 1 if ack(3, 0) == 5: count1 = count1 + 1 if ack(0, 1) == 2: count1 = count1 + 1 if ack(1, 1) == 3: count1 = count1 + 1 if ack(2, 1) == 5: count1 = count1 + 1 if ack(3, 1) == 13: count1 = count1 + 1 if ack(0, 2) == 3: count1 = count1 + 1 if ack(1, 2) == 4: count1 = count1 + 1 if ack(2, 2) == 7: count1 = count1 + 1 if ack(3, 2) == 29: count1 = count1 + 1 if ack(0, 3) == 4: count1 = count1 + 1 if ack(1, 3) == 5:
from ack import ack facts = open("facts/facts.csv").read().split('\n') for fact in facts: parts = fact.split(',') m, n, expected = [int(i) for i in parts] stack = [-1, m, n] ack(stack) assert stack[-1] == expected
import ack ack.ack(0,1) print "hi"
def test_ack_0(): assert ack(0, 0) == 1 assert ack(0, 1) == 2 assert ack(0, 2) == 3 assert ack(0, 3) == 4 assert ack(0, 4) == 5
def test_ack_3(): assert ack(3, 0) == 5 assert ack(3, 1) == 13 assert ack(3, 2) == 29 assert ack(3, 3) == 61 assert ack(3, 4) == 125
def test_ack_2(): assert ack(2, 0) == 3 assert ack(2, 1) == 5 assert ack(2, 2) == 7 assert ack(2, 3) == 9 assert ack(2, 4) == 11
def test_ack_1(): assert ack(1, 0) == 2 assert ack(1, 1) == 3 assert ack(1, 2) == 4 assert ack(1, 3) == 5 assert ack(1, 4) == 6
import ack ack.ack(0, 1) print "hi"
def test_badvalues(): u"""Verify that only positive integers are processed by the fucntion.""" for badval in badvals: with pytest.raises(ValueError): result = ack.ack(badval[0], badval[1])