Source

aichallenge-py / test_torus.py

Full commit
# -*- coding: utf-8 -*-
#
#  test_torus.py
#  aichallenge-py
#
#  Created by Lars Yencken on 2011-11-13.
#  Copyright 2011 Lars Yencken. All rights reserved.
#

"""
Tests for locations on a torus.
"""

import unittest

import torus

class TorusTest(unittest.TestCase):
    def setUp(self):
        torus.init(15, 20)

    def test_add(self):
        l1 = torus.Loc(3, 5)
        l2 = torus.Loc(7, 8)
        self.assertEqual(l1 + l2, torus.Loc(10, 13))

        l3 = torus.Loc(14, 19)
        self.assertEqual(l1 + l3, torus.Loc(2, 4))

    def test_sub(self):
        l1 = torus.Loc(3, 5)
        l2 = torus.Loc(7, 8)
        self.assertEqual(l2 - l1, torus.Loc(4, 3))

        l3 = torus.Loc(4, 6)
        self.assertEqual(l1 - l3, torus.Loc(14, 19))

    def test_dist(self):
        l1 = torus.Loc(3, 5)
        l2 = torus.Loc(7, 8)
        self.assertEqual(l1.dist(l2), 7)
        self.assertEqual(l2.dist(l1), 7)

        l3 = torus.Loc(14, 19)
        self.assertEqual(l1.dist(l3), 10)
        self.assertEqual(l3.dist(l1), 10)

    def test_dest(self):
        l = torus.Loc(0, 0)
        self.assertEqual(l.dest('n'), torus.Loc(14, 0))
        self.assertEqual(l.dest('s'), torus.Loc(1, 0))
        self.assertEqual(l.dest('e'), torus.Loc(0, 1))
        self.assertEqual(l.dest('w'), torus.Loc(0, 19))

if __name__ == '__main__':
    unittest.TextTestRunner(verbosity=1).run(unittest.makeSuite(TorusTest))