Commits

gabriele renzi  committed d8502c7

guess works and tested

  • Participants
  • Parent commits b991fb3

Comments (0)

Files changed (2)

File example/guess.spl

+The guessing game, by Jonas Sjöbergh, jsh@nada<dot>kth<dot>se, 
+think of a number between 1 and 1000, if the program's guess is
+too high input "<", if it is too low input ">" and if it is correct
+input "=".
+
+Romeo, with an open mind.
+Juliet, the guess(t).
+Emilia, up and about.
+Bianca, feeling low.
+Oberon, everyones equal.
+Desdemona, feeds lines to others.
+Helen, returns with a carriage.
+Hamlet, marks a question.
+
+		   Act I: A guess comes to dinner.
+
+		     Scene I: The introductions.
+[Enter Romeo and Desdemona]
+Romeo:
+	Thou art as fine as the sum of a pretty flower and a
+	lovely smooth rich plum.
+[Exit Desdemona]
+[Enter Emilia]
+Romeo:
+	Thou art as charming as the cube of Desdemona.
+[Exit Emilia]
+[Enter Helen]
+Romeo:
+	Thou art as fine as the sum of Desdemona and the sum of a red
+	rose and a flower.
+[Exit Helen]
+[Enter Bianca]
+Romeo:
+	Thou art as warm as a summer's day.
+[Exit Bianca]
+[Enter Oberon]
+Romeo:
+	Thou art as foul as the sum of a little tiny furry white old
+	animal and a smelly toad. Thou art as disgusting as the product of thyself and
+	a horrible hog. Thou art as evil as the difference between a
+	cow and thyself.
+[Exit Oberon]
+[Enter Hamlet]
+Romeo:
+	Thou art as disgusting as the sum of Oberon and a big cow.
+
+		      Scene II: The repetitions.
+[Exeunt]
+[Enter Romeo and Juliet]
+Romeo:
+	Thou art as lovely as the sum of Emilia and Bianca. Thou art
+	as sweet as the quotient between thyself and a little flower.
+	Open your heart.
+[Exit Juliet]
+[Enter Hamlet]
+Romeo:
+	Speak your mind.
+		   Scene III: In case of foul play.
+[Exeunt]
+[Enter Romeo and Juliet]
+Juliet:
+	Open your mind.
+[Exit Juliet]
+[Enter Helen]
+Romeo:
+	Speak your mind.
+[Exit Helen]
+[Enter Desdemona]
+Romeo: 
+	Speak your mind.
+Romeo:
+	Am I as brave as Oberon? If so, let us proceed to Scene VI.
+	Am I as bold as the sum of Oberon and a pig? If so, let us proceed to Scene IV.
+	Am I as cunning as the sum of Oberon and a cow? If so, let us proceed to Scene V.
+	Let us proceed to Scene III.
+
+		    Scene IV: Where less is more.
+[Exeunt]
+[Enter Emilia and Juliet]
+Emilia:
+	Am I as good as the sum of Bianca and a flower? If so, thou
+	art as fine as Bianca.  
+Juliet:
+	Remember me. Recall that I am your friend. Let us return to Scene II. 
+
+		    Scene V: Where more is needed.
+[Exeunt]
+[Enter Bianca and Juliet]
+Bianca:
+	Am I as good as the difference between Emilia and a flower? If so, thou
+	art as fine as Emilia.
+	Am I as good as the difference between Emilia and a red rose? If so, thou
+	art as fine as Emilia.
+Juliet:
+	Remember me. Recall that I am your friend. Let us return to Scene II. 
+
+			  Scene VI: The End.
+[Exeunt]
+[Enter Romeo and Juliet]
+Romeo:
+	Open your heart.
+[Exeunt]
+[Enter Helen and Desdemona]
+Desdemona:
+	Speak your mind.
+Helen:
+	Speak your mind.
 
 DIR=File.join(File.dirname(__FILE__),'..')
 
-puts "1..74"
+puts "1..#{45+1+1+26+1+11}"
 def with_prog(name)
   p str= %W[../../parrot z2.pir example/#{name}.spl].map{|x| File.join(DIR,x)}*" "
   IO.popen(str,'r+') do |io|
   if x==y
     puts "ok #$i"
   else
-    puts "not ok #$i -- #{x} expected but got #{y}"
+    puts "not ok #$i -- #{x.inspect} expected but got #{y.inspect}"
   end
 end
 
 with_prog 'fibonacci2' do |p|
   DATA.each do |o|
-    is o, p.readline
+    is o, p.gets
   end
 end
 
 
 with_prog 'hello' do |prog|
-  is STR, prog.readline
+  is STR, prog.gets
 end
 
 with_prog 'reverse' do |prog|
   prog.write('100\n')
   prog.close_write
   ary.each do |el|
-    is el, prog.readline.chomp
+    is el, prog.gets.chomp
   end
 end
 
   prog.puts('1')
   prog.puts('5')
   prog.close_write
-  is '6', prog.readline.chomp
+  is '6', prog.gets.chomp
+end
+
+with_prog 'guess' do |prog|
+  inp=%w[> > < > < > > > < =]
+  out=%w(500?  750?  875?  812?  843?  827?  835?  839?  841?  840?  840)
+  o = out.shift
+  is o,x=prog.read(4)
+  out.each do |o|
+    str= inp.shift
+    prog.puts(str)
+    prog.gets
+    x=prog.gets
+    is o,x.strip
+  end
 end
 __END__
 0