Sha256: 047d98dcbf9b847d0faac90d08585d9d2d4b6431c4e9b4f6d4b2fa0d62663467
Contents?: true
Size: 1.71 KB
Versions: 2
Compression:
Stored size: 1.71 KB
Contents
require 'spec_helper' describe Stroop::ColorGenerator do describe 'without seed' do subject { described_class.new } describe '#generate' do it 'returns a random color' do expect(Stroop::ColorGenerator::COLORS).to include subject.generate end end describe '#generate_pair' do it 'returns a pair of colors that are different' do 20.times do first, second = subject.generate_pair expect(first).to_not eq second end end it 'returns another pair in subsequent calls' do previous_colors = subject.generate_pair 20.times do new_colors = subject.generate_pair expect(new_colors).to_not eq previous_colors previous_colors = new_colors end end end describe 'with seed' do let(:seed) { 1234 } let(:generator) { described_class.new(seed: seed) } let(:other_generator) { described_class.new(seed: seed) } describe '#generate' do it 'uses the given seed to generate colors deterministically' do 20.times { expect(generator.generate).to eq other_generator.generate } end end describe '#generate_pair' do it 'uses the given seed to generate colors deterministically' do 20.times { expect(generator.generate_pair).to eq other_generator.generate_pair } end end it 'generates the same colors for #generate and #generate_pair (first color only)' do generated_colors = 20.times.map { generator.generate } generated_pairs_first_colors = 20.times.map { other_generator.generate_pair.first } expect(generated_colors).to eq generated_pairs_first_colors end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
stroop-1.2.0 | spec/stroop/color_generator_spec.rb |
stroop-1.1.0 | spec/stroop/color_generator_spec.rb |