Ejemplo n.º 1
0
 def test_crosstab(self):
     l1= [1, 2, 7, 7, 2, 1, 2, 1, 1]
     l2= [1, 3, 2, 6, 6, 3, 6, 4, 4]
     correct = np.array([('1', 1, 0, 1, 2, 0),
                         ('2', 0, 0, 1, 0, 2),
                         ('7', 0, 1, 0, 0, 1)],
                        dtype=[('col1_value', 'S1'),
                               ('1', int),
                               ('2', int),
                               ('3', int),
                               ('4', int),
                               ('6', int)])
     self.assertTrue(np.array_equal(correct, crosstab(l1,l2)))
Ejemplo n.º 2
0
    def test_crosstab(self):
        l1= [1, 2, 7, 7, 2, 1, 2, 1, 1]
        l2= [1, 3, 2, 6, 6, 3, 6, 4, 4]
        correct = np.array([('1', 1, 0, 1, 2, 0),
                            ('2', 0, 0, 1, 0, 2),
                            ('7', 0, 1, 0, 0, 1)],
                           dtype=[('col1_value', 'S1'),
                                  ('1', int),
                                  ('2', int),
                                  ('3', int),
                                  ('4', int),
                                  ('6', int)])
        correct_printout = """
  col1_value 1 2 3 4 6
0          1 1 0 1 2 0
1          2 0 0 1 0 2
2          7 0 1 0 0 1
        """.strip()
        with uft.rerout_stdout() as get_stdout:
            self.assertTrue(np.array_equal(correct, crosstab(l1,l2)))
            self.assertEqual(get_stdout().strip(), correct_printout)