Software Development (CSC 321 2015F) : EBoards
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] [FAQ] [Teaching & Learning]
Sections: [Assignments] [EBoards] [Examples] [Handouts] [Outlines]
Reference: [Slack] [Ruby@CodeCademy]
Related Courses: [CSC 321 2015F @ EdX] [Berkeley CS 169 2014F] [CSC 321 2015S (Davis)] [CSC 322 2015F (Rebelsky)]
Misc: [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] [Issue Tracker]
Overview
hw-bdd-tdd-cycle
when you cloneclass TimeSetter def self.convert(d) y = 1980 while (d > 365) do if ((y % 400 == 0) || ((y % 4 == 0) && (y % 100 != 0))) if (d > 366) d -= 366 y += 1 end else d -= 365 y += 1 end end return [y,d] end end
What does this program try to do?
What is wrong with this program?
How would we find it?
How would we fix it?
class TimeSetter def self.isLeapYear(year) ((year % 400) == 0) || ((year % 4 == 0) && (year % 100 != 0)) end def self.daysInYear(year) if isLeapYear(year) 366 else 365 end end def self.convert(d) y = 1980; while (d > daysInYear(y)) d -= daysInYear(y) y += 1 end return [y,d] end end
A technique for developing correct loop code and think through what your code does.
Three parts
Note:
As we write any algorithm, it's useful to know what all the variables represent.
Pure TDD
Reality