Source

aichallenge-py / test_torus.py

# -*- 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)