Anonymous user
Ethiopian multiplication: Difference between revisions
m
→{{header|Ruby}}: move tests for clarity
m (→{{header|C++}}: Broke a long line) |
m (→{{header|Ruby}}: move tests for clarity) |
||
Line 1,400:
$DEBUG = true # $DEBUG also set to true if "-d" option given
a, b = 20, 5
puts "#{a} * #{b} = #{ethopian_multiply(a,b)}"; puts</lang>
Output:▼
<pre>[20, 5, "STRIKE"]▼
require 'test/unit'▼
[10, 10, "STRIKE"]▼
[5, 20, "KEEP"]▼
[2, 40, "STRIKE"]▼
[1, 80, "KEEP"]▼
20 * 5 = 100</pre>▼
A test suite:
▲<lang ruby>require 'test/unit'
class EthiopianTests < Test::Unit::TestCase
def test_iter1; assert_equal(578, ethopian_multiply(17,34)); end
Line 1,418 ⟶ 1,426:
def test_rec6; assert_equal(0, rec_ethopian_multiply(0,5)); end
end</lang>
<pre>Loaded suite ethopian▼
▲Output:
▲<pre>[20, 5, "STRIKE"]
▲[10, 10, "STRIKE"]
▲[5, 20, "KEEP"]
▲[2, 40, "STRIKE"]
▲[1, 80, "KEEP"]
▲20 * 5 = 100
▲Loaded suite ethopian
Started
............
Line 1,432:
12 tests, 12 assertions, 0 failures, 0 errors</pre>
=={{header|Scheme}}==
In Scheme, <code>even?</code> is a standard procedure.
|