def test_init(self): results = { 1: [Result.parse('1nn='), Result.parse('1nn+1')], 2: [Result.parse('4ss='), Result.parse('4ss-1')] } rs = VugraphRS(results) self.assertEqual(rs.results, results)
def test_parse_none_missing(self): rs = VugraphRS.parse('1nw+3,1nw+3,5de=,5dw+1,2ns=,3cs-1,4sw=,4sw=') self.assertEqual(rs.results[0][0], Result.parse('1nw+3')) self.assertEqual(rs.results[0][1], Result.parse('1nw+3')) self.assertEqual(rs.results[1][0], Result.parse('5de=')) self.assertEqual(rs.results[1][1], Result.parse('5dw+1')) self.assertEqual(rs.results[2][0], Result.parse('2ns=')) self.assertEqual(rs.results[2][1], Result.parse('3cs-1')) self.assertEqual(rs.results[3][0], Result.parse('4sw=')) self.assertEqual(rs.results[3][1], Result.parse('4sw='))
def test_parse_with_gaps(self): rs = VugraphRS.parse(',,,,1nw+3,1nw+3,5de=,5dw+1,2ns=,3cs-1,4sw=,4sw=') self.assertFalse(0 in rs.results) self.assertFalse(1 in rs.results) self.assertEqual(rs.results[2][0], Result.parse('1nw+3')) self.assertEqual(rs.results[2][1], Result.parse('1nw+3')) self.assertEqual(rs.results[3][0], Result.parse('5de=')) self.assertEqual(rs.results[3][1], Result.parse('5dw+1')) self.assertEqual(rs.results[4][0], Result.parse('2ns=')) self.assertEqual(rs.results[4][1], Result.parse('3cs-1')) self.assertEqual(rs.results[5][0], Result.parse('4sw=')) self.assertEqual(rs.results[5][1], Result.parse('4sw='))
def test_repr(self): self.assertEqual(str(Result.parse('1cn=')), '1cn=') self.assertEqual(str(Result.parse('2ds-1')), '2ds-1') self.assertEqual(str(Result.parse('3ne+1')), '3ne+1') self.assertEqual(str(Result.parse('4hw-2')), '4hw-2') self.assertEqual(str(Result.parse('5snx+2')), '5snx+2') self.assertEqual(str(Result.parse('6csxx=')), '6csxx=')
def parse(rs): results_list = rs.split(',') results = {} index = 0 while index < len(results_list): result_str = results_list[index] if '' != result_str: result = Result.parse(result_str) deal = index // 2 if deal not in results: results[deal] = [] results[deal].append(result) index += 1 return VugraphRS(results)
def test_parse_invalid(self): with self.assertRaises(Exception): Result.parse('8cn=') # 8 not a valid level with self.assertRaises(Exception): Result.parse('1xs=') # x not a valid suit with self.assertRaises(Exception): Result.parse('1cx=') # x not a valid declarer with self.assertRaises(Exception): Result.parse('1cn') # missing score with self.assertRaises(Exception): Result.parse('1cn=0') # unexpected trailing 0 with self.assertRaises(Exception): Result.parse('1cn-8') # -8 not valid result with self.assertRaises(Exception): Result.parse('1cn+8') # +8 not valid result
def test_parse_valid(self): self.assertEqual(str(Result.parse('1cn=')), '1cn=') self.assertEqual(str(Result.parse('2ds-1')), '2ds-1') self.assertEqual(str(Result.parse('3ne+1')), '3ne+1') self.assertEqual(str(Result.parse('4hw-2')), '4hw-2') self.assertEqual(str(Result.parse('5snx+2')), '5snx+2') self.assertEqual(str(Result.parse('6csxx=')), '6csxx=') self.assertEqual(str(Result.parse('1CN=')), '1cn=') self.assertEqual(str(Result.parse('2DS-1')), '2ds-1') self.assertEqual(str(Result.parse('3NE+1')), '3ne+1') self.assertEqual(str(Result.parse('4HW-2')), '4hw-2') self.assertEqual(str(Result.parse('5SNX+2')), '5snx+2') self.assertEqual(str(Result.parse('6CSXX=')), '6csxx=')