From: James Edward Gray II Date: 2006-07-04T00:08:41+09:00 Subject: Re: [QUIZ] C-Style Ints (#85) - not a spoiler, a test harness On Jul 1, 2006, at 7:39 PM, Daniel Martin wrote: > I do take issue with one of your tests, though: > >> def test_power >> uint3 = UnsignedFWI(3) >> assert_equal(2, 2 ** uint3.new(1)) >> assert_equal(0, 2 ** uint3.new(3)) >> assert_equal(0, 2 ** uint3.new(67)) >> assert_equal(1, 3 ** uint3.new(2)) >> assert_equal(3, uint3.new(3) ** uint3.new(-1)) # 3**7 mod 8 >> end > > That just feels wrong. (except for the last one) I would write: > > def test_power > uint3 = UnsignedFWI(3) > assert_equal(2, uint3.new(2) ** 1) > assert_equal(0, uint3.new(2) ** 3) > assert_equal(0, uint3.new(2) ** 67) > assert_equal(1, uint3.new(3) ** 2) > assert_equal(3, uint3.new(3) ** uint3.new(-1)) # 3**7 mod 8 > end > > And maybe: > > def test_power_fwi_exponent > uint3 = UnsignedFWI(3) > assert_equal(2, 2 ** uint3.new(1)) > assert_equal(8, 2 ** uint3.new(3)) > assert_equal(8, 2 ** uint3.new(67)) > end > > I really think that you want to keep exponentiation looking like > repeated multiplication of the first argument. I think that's a good point. > Of course, it would be nice if our kind quiz host would respond with a > few rulings for the edge cases I outlined before. At least then we'd > know when we were ignoring the rules of the quiz. The main rule: Do what you feel is right. If you explain why you make the choices you do and convince me you are right, I'll talk about how clever you are in the summary. ;) Sorry I wasn't around this weekend. I felt it better to be hard to reach for a couple of days than to cancel this week's quiz altogether. James Edward Gray II