Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.39 KB | None | 0 0
  1. class Game
  2.     PUNTOS = [0,15,30,40]
  3.  
  4.     def initialize
  5.         @jugadores = {"j1"=> 0,"j2"=>0}
  6.        
  7.     end
  8.     def score
  9.         if is_deuce?
  10.             "DEUCE"
  11.         else
  12.             "#{PUNTOS[@jugadores['j1']]}-#{PUNTOS[@jugadores['j2']]}"
  13.         end
  14.     end
  15.  
  16.     def pointTo jugador
  17.         @jugadores[jugador] += 1
  18.     end
  19.  
  20. private
  21.  
  22.     def is_deuce?
  23.         @jugadores['j1'] == 3 and @jugadores['j2'] == 3
  24.     end
  25. end
  26.  
  27.  
  28.  
  29.  
  30. -------------------------------------------------
  31.  
  32.  
  33.  
  34. require './lib/game'
  35.  
  36. describe Game do
  37.     it "el partido inicia 0-0" do
  38.         game=Game.new
  39.         expect(game.score).to eq "0-0"
  40.     end
  41.  
  42.     it "j1 marca y el partido va 15-0" do
  43.         game=Game.new
  44.         game.pointTo("j1")
  45.         expect(game.score).to eq "15-0"
  46.     end
  47.  
  48.     it "j1 marca 2 veces y el partido va 30-0" do
  49.         game=Game.new
  50.         game.pointTo("j1")
  51.         game.pointTo("j1")
  52.         expect(game.score).to eq "30-0"
  53.     end
  54.  
  55.     it "j1 marca 3 veces y el partido va 40-0" do
  56.         game=Game.new
  57.         game.pointTo("j1")
  58.         game.pointTo("j1")
  59.         game.pointTo("j1")
  60.         expect(game.score).to eq "40-0"
  61.     end
  62.  
  63.     it "j2 marca 3 veces y el partido va 0-40" do
  64.         game=Game.new
  65.         game.pointTo("j2")
  66.         game.pointTo("j2")
  67.         game.pointTo("j2")
  68.         expect(game.score).to eq "0-40"
  69.     end
  70.  
  71.     it "el partido debe ir en deuce" do
  72.         game=Game.new
  73.         game.pointTo("j2")
  74.         game.pointTo("j2")
  75.         game.pointTo("j2")
  76.         game.pointTo("j1")
  77.         game.pointTo("j1")
  78.         game.pointTo("j1")
  79.         expect(game.score).to eq "DEUCE"
  80.     end
  81. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement