RSpec.configure do |config|
# Use color in STDOUT
config.color_enabled = true
# Use color not only in STDOUT but also in pagers and files
config.tty = true
# Use the specified formatter
config.formatter = :documentation # :progress, :html, :textmate
end
# run this file at the command line: rspec blog_post_scheduler_spec.rb
# remember that tests can be your to-do list, and that you should get one
# test to pass at a time, doing the simplest thing you can for each one.
# read your rspec output carefully to find what you need to fix. the errors
# will guide you!
require_relative './spec_helper.rb'
require_relative './blog_post_scheduler.rb'
describe "Blog Post Scheduler" do
describe "#create_groups" do
let (:group_size) { 4 }
let (:students) { get_students }
it "returns an array of groups" do
create_groups(students, group_size, 20).class.should eq(Array)
end
it "sets group sizes to the size given" do
create_groups(students, group_size, 20).first.size.should eq(group_size)
end
it "creates the right number of groups" do
pending "implement a test that ensures you get the right number of groups returned"
end
it "uses every student in the list for a large enough number of groups" do
groups = create_groups(students, group_size, 11)
students.sort.should eq(groups.flatten.uniq.sort)
end
it "attempts to randomize the list" do
pending "implement a test that ensures that the list order returned is different from the student list"
#hint: look at the test: 'it uses every student in the list...'
end
it "uses some studens more than once for a large enough number of groups" do
groups = create_groups(students, group_size, 1000)
groups.each do |group|
group.size.should eq(group_size)
end
end
it "doesn't repeat students on adjacent days" do
groups = create_groups(students, group_size, 20)
groups.each_with_index do |group, i|
(group & groups[i+1]).should eq([]) if i < groups.size - 1
# the bitwise & (not &&) operator creates an array that
# is the intersection of two arrays, meaning the common
# elements. Try this in IRB by creating:
# array1 = [1,2,3]
# array2 = [4,5,6]
# array3 = [1,5,9]
# then type array1 & array2, array1 & array3, etc
# This single line test is the equivalent of doing:
#group.each do |g|
#groups[i+1].include?(g).should be_false if i < groups.size - 1
#end
end
end
end
end
def get_students
[
"Alex Chiu",
"Amanda Himmelstoss",
"Anders Ramsay",
"Bana Malik",
"Brendan Manley",
"Charlotte Chang",
"Christopher Lee",
"Daniel Chang",
"David Bella",
"Edina Vath",
"Emily Xie",
"Greg Eng",
"Ian Miller",
"Iris Lee",
"Ivan Brennan",
"James Tong",
"Jeanne Roniger",
"Joe O'Conor",
"John Richardson",
"Joshua Scaglione",
"Kyle Shike",
"Logan Hasson",
"Manuel Neuhauser",
"Margaret Lee",
"Matt Campbell",
"Michael Polycarpou",
"Mike Spangler",
"Raymond Gan",
"Rosanne Hoyem",
"Sam Yang",
"Samuel Owens",
"Saron Yitbarek",
"Scott Luptowski",
"Vivian Zhang",
"Sonja Hall",
"Stephanie Oh",
"Theo Vora",
"Thomas Surgent",
"Tiffany Peon",
"Trevor McKendrick",
"Vinney Cavallo"
]
end
#create a method called create_groups that, given an array of student names,
#a group size, and a number of groups, will return an array of groups of
#of students with no student in adjacent groups