connect four (game)

Ian Kelly ian.g.kelly at gmail.com
Fri Nov 24 23:43:09 EST 2017


On Fri, Nov 24, 2017 at 7:05 PM,  <namenobodywants at gmail.com> wrote:
> On Friday, November 24, 2017 at 12:13:18 PM UTC-8, Terry Reedy wrote:
>
>> Since you did not start with tests or write tests as you wrote code, ...
>
> why on earth would you assume that? instantiate "window" and you'll see it works exactly as i intended; nobody's asking you to debug code for free; i'm looking for the kind of feedback the other respondent gave

Since you're being a bit of an ass about it, I took the liberty of
writing some tests for you. This only covers the very first class in
the file (I don't have all night). Two of the tests pass. The others
don't.

Since the interface is unclear (is signum allowed to be any signed
number, or only +/-1? The ordered comparison methods suggest the
former, but __eq__ only works with the latter) I chose to be
conservative and only wrote tests with +/-1. Otherwise test_eq would
also fail.

Please understand the point of this is not to shame you or anything.
As you said, we're not going to debug your code for you, but you asked
for criticism/suggestions, and I hope to make you see that suggesting
you write tests is a very valid and useful criticism of its own.


###############################
#) connectfour_test - python 3.6.1
###############################

import unittest

from connectfour import infinity


class InfinityTest(unittest.TestCase):

    def test_repr(self):
        self.assertEqual('+oo', repr(infinity(+1)))
        self.assertEqual('-oo', repr(infinity(-1)))

    def test_lt(self):
        self.assertLess(infinity(-1), infinity(+1))
        self.assertFalse(infinity(-1) < infinity(-1))
        self.assertFalse(infinity(+1) < infinity(+1))
        self.assertFalse(infinity(+1) < infinity(-1))

    def test_le(self):
        self.assertLessEqual(infinity(-1), infinity(+1))
        self.assertLessEqual(infinity(-1), infinity(-1))
        self.assertLessEqual(infinity(+1), infinity(+1))
        self.assertFalse(infinity(+1) <= infinity(-1))

    def test_gt(self):
        self.assertFalse(infinity(-1) > infinity(+1))
        self.assertFalse(infinity(-1) > infinity(-1))
        self.assertFalse(infinity(+1) > infinity(+1))
        self.assertGreater(infinity(+1), infinity(-1))

    def test_ge(self):
        self.assertFalse(infinity(-1) >= infinity(+1))
        self.assertGreaterEqual(infinity(-1), infinity(-1))
        self.assertGreaterEqual(infinity(+1), infinity(+1))
        self.assertGreaterEqual(infinity(+1), infinity(-1))

    def test_eq(self):
        self.assertEqual(infinity(-1), infinity(-1))
        self.assertEqual(infinity(+1), infinity(+1))
        self.assertNotEqual(infinity(-1), infinity(+1))
        self.assertNotEqual(infinity(+1), infinity(-1))


if __name__ == '__main__':
    unittest.main()



More information about the Python-list mailing list