Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Game
- PUNTOS = [0,15,30,40]
- def initialize
- @jugadores = {"j1"=> 0,"j2"=>0}
- end
- def score
- if is_deuce?
- "DEUCE"
- else
- "#{PUNTOS[@jugadores['j1']]}-#{PUNTOS[@jugadores['j2']]}"
- end
- end
- def pointTo jugador
- @jugadores[jugador] += 1
- end
- private
- def is_deuce?
- @jugadores['j1'] == 3 and @jugadores['j2'] == 3
- end
- end
- -------------------------------------------------
- require './lib/game'
- describe Game do
- it "el partido inicia 0-0" do
- game=Game.new
- expect(game.score).to eq "0-0"
- end
- it "j1 marca y el partido va 15-0" do
- game=Game.new
- game.pointTo("j1")
- expect(game.score).to eq "15-0"
- end
- it "j1 marca 2 veces y el partido va 30-0" do
- game=Game.new
- game.pointTo("j1")
- game.pointTo("j1")
- expect(game.score).to eq "30-0"
- end
- it "j1 marca 3 veces y el partido va 40-0" do
- game=Game.new
- game.pointTo("j1")
- game.pointTo("j1")
- game.pointTo("j1")
- expect(game.score).to eq "40-0"
- end
- it "j2 marca 3 veces y el partido va 0-40" do
- game=Game.new
- game.pointTo("j2")
- game.pointTo("j2")
- game.pointTo("j2")
- expect(game.score).to eq "0-40"
- end
- it "el partido debe ir en deuce" do
- game=Game.new
- game.pointTo("j2")
- game.pointTo("j2")
- game.pointTo("j2")
- game.pointTo("j1")
- game.pointTo("j1")
- game.pointTo("j1")
- expect(game.score).to eq "DEUCE"
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement