Created
October 2, 2013 13:03
-
-
Save scottcreynolds/6793378 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 | |
def create_groups(student_array, group_size, number_of_groups) | |
student_list = student_array.shuffle | |
groups = [] | |
number_of_groups.times do | |
s = student_list.shift(group_size) | |
groups << s | |
student_list.push(s) | |
student_list = student_list.flatten | |
end | |
groups | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
create_groups(students, group_size, 25).size.should eq(25) | |
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 | |
groups = create_groups(students, group_size, 20) | |
students.should_not eq(groups.flatten.uniq) | |
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment