On 25/11/2017 04:43, Ian Kelly wrote:
On Fri, Nov 24, 2017 at 7:05 PM,  <namenobodywa...@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()

Where are your unittests for these unittests?

Or is this kind of code immune from testing?

Actually I've no idea what these tests are supposed to prove. They are to do with one class called 'infinity', which is never used in the rest of the program apart from one line.

I established that within a few seconds, and I would concentrate on what 'infinity' is actually for, rather than go to considerable lengths to test a class that may not actually be needed.

And there's a quite lot left of the rest of the program to worry about too!

If you add 'window()' at the end of the program, then it seems to run on Python 3. I'd play around with it first before thinking up strategies for testing it.

--
bartc
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to