Sha256: 9ca01a6624cb7f46ce3007bed35f2c0a99a6378a5bdad82f637894c193f31bd4

Contents?: true

Size: 1.15 KB

Versions: 1

Compression:

Stored size: 1.15 KB

Contents

require 'spec_helper'

describe "tournamenting a game of street fighter" do

  Player = Struct.new(:name, :hero)

  # Perform a random battle, giving the hero 3 chances to win to every
  # 1 chance for the opponent. We must return the winner wrapped in a `Left`
  # if the winner is the opponent, or a `Right` if the winner is our hero.
  def battle(opponent, hero)
    winner = ([hero] * 3 << opponent).sample
    winner.hero ? StreetFighter::Right.new(winner) :
                  StreetFighter::Left.new(winner)
  end


  it "always returns a Left or a Right value" do
    ryu   = Player.new(:ryu, true)    # The hero!

    # The bad guys.
    retsu = Player.new(:retsu, false)
    geki  = Player.new(:geki,  false)
    joe   = Player.new(:joe,   false)

    fight = method(:battle).to_proc.curry

    winner = StreetFighter.tournament(ryu, fight[retsu], fight[geki], fight[joe])

    # case winner
    # when StreetFighter::Left
    #   puts "Our hero has been defeated, and #{winner.value.name} is the new champion."
    # when StreetFighter::Right
    #   puts "Ryu has defeated his opponents!"
    # end

    winner.must_be_kind_of StreetFighter::EitherValue
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
street_fighter-0.0.1 spec/street_fighter/street_fighter_game_spec.rb