Note:
Testo rimosso dalla rev 5 e
Testo aggiunto nella rev6
Nello spirito di Peter Seibel qui di seguito i risultati della disfida. Le regole erano:
- non importa il linguaggio
- vince chi ha il codice piu’ compatto
- il codice deve essere capito almeno da 4 altri componenti del team ==> verranno brutalmente contati i \n, splittando in automatico le righe quando diventano piu’ lunghe di 70 chars
- nessun limite al numero di classi, metodi, ecc.
- non e’ necessario che il codice sia OO
- funzionalmente non e’ richiesto che faccia niente di piu’ dello step finale dell’articolo, cioe’ il tutto deve essere comprensivo di qualche esempio (il codice di esempio non rientra nel conto)
Il guanto della sfida e’ stato lanciato il 2-2-04, con verifica dei risultati l’1-3-04
Vincitore: VAA!!!!
VAA – Ruby
# test.rb require "rut.rb" def testPlus check( "1+2 == 4", "1+2+3 == 6", "-1 -3 == -4" ) end def testStar check( "2*2 == 4", "3*2 == 6" ) end def testArithmetic combine( testPlus, testStar ) end def testMath testArithmetic end puts testMath # rut.rb def combine(*results) not results.flatten().include? false end def check (*all) combine all.collect{|t|c =caller-[caller.last] c.collect!{|l|(l.include? "rut.rb")? nil : l.sub(/.*in/, '')} puts (eval t)?"pass ...#{c} #{t}":"FAIL ...#{c} #{t}";eval t} end
VAD – Smalltalk
Trigo class >> check: what what size = 0 ifTrue: [^true] ifFalse: [^(Trigo report: (what at: 1)) & (Trigo check: (what copyFrom: 2 to: what size))] Trigo class >> filter ^((thisContext sendersTo: nil) select: [:each | '*test*' match: each printString]) reverse Trigo class >> report: aTest | result eval | eval := Compiler evaluate: aTest. eval ifTrue:[result:=': pass'] ifFalse:[result:=': FAIL']. Trigo filter do:[:each|Transcript show:each printString,' ' ]. Transcript show: aTest, result, '\' withCRs.^eval
QUA – Perl
# conTest 01: sub makeTest { 02: my $testname = shift; 03: my @tests = map { ref $_ ? $_ : makeTestRunner($_) } @_; 04: return sub { my $suitename=shift; our $level++; my $result=1; 05: map { $result &= $_->($suitename.$testname.' ') } @tests; 06: --$level == 0 ? print $result ? "T":"F","\n" : $result; } } 07: sub makeTestRunner { 08: my $code = shift; return sub { my $result = eval $code; 09: print $result?"pass":"fail"," ... ( ".shift().") $code\n"; 10: $result ? 1:0 } } "End of conTest :-)"; # examplePass use strict; use lib "."; require "conTest.pl"; my $testPlusMinus = makeTest("TestPlusMinus", "1+2==3", "1+1==2", "5+2==7"); $testPlusMinus->(); print "---------------------------------------------------\n"; my $testMultiply = makeTest("TestMultiply", "1*2==2", "2*2==4"); $testMultiply->(); print "---------------------------------------------------\n"; my $testArithmetic = makeTest("TestArithmetic", $testPlusMinus, $testMultiply); $testArithmetic->(); print "---------------------------------------------------\n"; my $testMath = makeTest("TestMath", $testArithmetic); $testMath->(); # exampleFail use strict; use lib "."; require "conTest.pl"; my $testPlusMinus = makeTest("TestPlusMinus", "1+2==3", "1+1==2", "5+2==7"); $testPlusMinus->(); print "---------------------------------------------------\n"; my $testMultiply = makeTest("TestMultiply", "1*2==2", "2*2==5"); $testMultiply->(); print "---------------------------------------------------\n"; my $testArithmetic = makeTest("TestArithmetic", $testPlusMinus, $testMultiply); $testArithmetic->(); print "---------------------------------------------------\n"; my $testMath = makeTest("TestMath", $testArithmetic); $testMath->();
Fuori concorso: BOP – Ruby
def check(*tests) stack = caller.map {|m| m[/\w*(?=')/]}.reverse.join(" ").strip tests.map {|t| puts "#{(v=eval(t))?'pass':'FAIL'} ... (#{stack}) #{t}"; v}.all? end def test_plus check( "1 + 2 == 3", "1 + 2 + 3 == 6", "-1 + -3 == -4") end def test_multiply check( "2 * 2 == 4", "3 * 5 == 15") end def test_aritmetic [test_plus, test_multiply].all? end def test_math test_aritmetic end result = test_math puts "result=#{result}"
—PiergiulianoBossiPiergiulianoBossi