示例#1
0
 def setUp(self):
     if not os.path.isfile("./cards"):
         self.skipTest("Program doesn't exist")
     self.rc, self.r = run("./cards")
     self.r = lines(self.r)
     self.assertGreater(self.rc, -1, "Program crashed!")
     self.assertEqual(self.rc, 0, "Program returned nonzero")
示例#2
0
 def setUp (self):
   if self.expect is False: self.expect_fail = True
   a = [self.arg1]
   if self.arg2 is not None: a.append(self.arg2)
   a = [str(x) for x in a]
   if not os.path.isfile("./tokenize"): self.skipTest("Program doesn't exist")
   self.rc,self.r = run("./tokenize", *a)
示例#3
0
    def _test_suits_seem_random(self, num):
        if not os.path.isfile("./cards"):
            self.skipTest("Program doesn't exist")
        self.ok = False
        srand = "call srand(%s)" % (num, )
        self.rc, self.r = run(*[
            "gdb", "./cards", "-ex", "break main", "-ex", "r", "-ex", srand,
            "-ex", "c", "-ex", "q"
        ])
        self.r = self.r.split("\nContinuing.\n", 1)[1]
        self.r = self.r.rsplit("[", 1)[0].strip()
        self.r = lines(self.r)
        self.assertGreater(self.rc, -1, "Program crashed!")
        self.assertEqual(self.rc, 0, "Program returned nonzero")

        cards = [x.lower().split(" of ") for x in self.r]

        rankname = lambda r: {
            1: "ace",
            11: "jack",
            12: "queen",
            13: "king"
        }.get(r, str(r))
        ac = [(rankname(r), s) for s in "hearts spades diamonds clubs".split()
              for r in range(1, 14)]

        counts = {c: 0 for c in ac}

        for c in cards:
            if len(c) != 2: self.skipTest("Bad deck")

            c = tuple(c)
            if c not in ac: self.skipTest("Bad deck")

            counts[c] += 1

        missing = {c for c, n in counts.items() if n == 0}
        multiple = {c for c, n in counts.items() if n > 1}

        if multiple or missing: self.skipTest("Bad deck")

        last_suit = None
        suit_switches = 0
        for c in cards:
            _, suit = c
            if last_suit is None:
                last_suit = suit
                continue
            if last_suit != suit:
                suit_switches += 1
            last_suit = suit

        self.ok = True
        self.assertGreater(suit_switches, 30)
示例#4
0
#!/usr/bin/env python

import spartan
import numpy as np
import test_common
from spartan.util import Assert


class LogicTest(test_common.ClusterTest):
    def test_logic(self):
        # Arange with no parameters.
        A = spartan.arange(40000, dtype=np.int32).reshape(100, 400)
        nA = np.arange(40000).reshape(100, 400)
        B = A.T
        nB = nA.T
        C = B / 1000
        nC = nB / 1000
        D = spartan.all(C)
        nD = np.all(nC)
        E = spartan.any(C)
        nE = np.any(nC)
        Assert.all_eq(D.glom(), nD)
        Assert.all_eq(E.glom(), nE)


if __name__ == '__main__':
    test_common.run(__file__)
示例#5
0
  
  print "#worker:", ctx.num_workers
  N = 100000 * ctx.num_workers
  D = 128
  
  # create data
  data = expr.randint(N, D, low=0, high=D, tile_hint=(N/ctx.num_workers, D))
  labels = expr.eager(expr.shuffle(data, _init_label_mapper))
    
  #util.log_warn('data:%s, label:%s', data.glom(), labels.glom())   
  
  util.log_warn('begin train')
  t1 = datetime.now()
  model = fit(data, labels, D)
  t2 = datetime.now()
  util.log_warn('train time:%s ms', millis(t1,t2))

  correct = 0
  for i in range(10):
    new_data = expr.randint(1, D, low=0, high=D, tile_hint=(1, D))
    new_label = predict(model, new_data)
    #print 'point %s, predict %s' % (new_data.glom(), new_label)
   
    new_data = new_data.glom()
    if np.isclose(new_data[0, new_label], np.max(new_data)):
      correct += 1
  print 'predict precision:', correct * 1.0 / 10
      
if __name__ == '__main__':
  test_common.run(__file__)
示例#6
0
 def setUp(self):
     if not os.path.isfile("./sizes"):
         self.skipTest("Program doesn't exist")
     self.rc, self.r = run("./sizes")