Skip to content

Instantly share code, notes, and snippets.

@zillou
Last active August 29, 2015 13:56
Show Gist options
  • Save zillou/9318757 to your computer and use it in GitHub Desktop.
Save zillou/9318757 to your computer and use it in GitHub Desktop.
Set operations in Ruby
# filename spec/fake_set_spec.rb
require 'spec_helper'
require 'fake_set'
describe FakeSet, '#union' do
set1 = FakeSet.new(1, 2, 3)
set2 = FakeSet.new(3, 4, 5)
expect(set1.union(set2)).to eq FakeSet.new(1, 2, 3, 4, 5)
end
describe FakeSet, '#intersect' do
set1 = FakeSet.new(1, 2, 3)
set2 = FakeSet.new(3, 4, 5)
expect(set1.intersect(set2)).to eq FakeSet.new(3)
end
describe FakeSet, '#difference' do
set1 = FakeSet.new(1, 2, 3)
set2 = FakeSet.new(3, 4, 5)
expect(set1.difference(set2)).to eq FakeSet.new(1 ,2)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment