From: Rob Biedenharn Date: 2008-10-11T01:07:43+09:00 Subject: Re: [QUIZ] Modular Arithmetic (#179) On Oct 10, 2008, at 11:13 AM, Matthew Moss wrote: > # The default modulus is 26. > > a = Modulo.new(15) > > b = Modulo.new(19) > > puts (a + b) > 8 > > puts (a - b) > 22 > > puts (b * 3) > 5 > > As noted in the example, you should use a modulus of 26 if none is > specified in the initializer. > def test_mul_int_reverse > a = Modulo.new(15, 8) > assert_equal(77, 11 * a) > end > > def test_non_default_modulo > a = Modulo.new(15, 11) > b = Modulo.new(9, 11) > > assert_equal(2, a + b) > assert_equal(6, a - b) > assert_equal(3, a * b) > end So I suppose the method signature would be documented something like: ------------------------------------------------------------- Modulo::new Modulo.new(value=0, modulus=26) ------------------------------------------------------------------------ Returns a new object that behaves according to the rules of Modular Arithmetic, but otherwise responds like an Integer from the set of integers between 0 and modulus-1. You never specifically said how an alternate modulus was indicated, but your tests give a good hint. -Rob Rob Biedenharn http://agileconsultingllc.com Rob@AgileConsultingLLC.com