Software Development (CSC 321 2016F) : EBoards
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] [FAQ] [Teaching & Learning]
Sections: [Assignments] [EBoards] [Examples] [Handouts] [Outlines]
Reference: [Slack] [Ruby@CodeCademy]
Related Courses: [Rails Tutorial] [CSC 321 2016S @ EdX] [CSC 321 2015S (Davis)] [CSC 321 2016S (Rebelsky)] [CSC 322 2016F (Rebelsky)]
Misc: [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] [Issue Tracker]
Overview
See http://www.cs.grinnell.edu/~rebelsky/s2d@g/
What does this program try to do?
class 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 [d,y]
end
end
What does this program try to do?
What tests would you run?
convert(366+365+365+365+366+1) = [1,1985]
Code coverage ...
What is wrong with this program?
How would we find it?
How would we fix it?
class TimeSetter
def self.convert(d)
// Set y to the start of time
y = 1980
// As long as we are beyond the end of the year
while (d > 365) do
// If it's a leap year
if ((y % 400 == 0) || (y % 4 == 0) && (y % 100 != 0))
// And there are enough days left in the year
if (d > 366)
// Move on to the next year
d -= 366
y += 1
end
else
// Move on to the next year
d -= 365
y += 1
end
end
return [d,y]
end
end
class TimeSetter
def self.convert(d)
// Let Y be 1980 and D be the initial value of d
y = 1980
// Invariant: Day D of 1980 is equivalent to day d of y.
// "Size": d
while (d > 365) do
if ((y % 400 == 0) || (y % 4 == 0) && (y % 100 != 0))
if (d > 366)
d -= 366
y += 1
// Maintains invariant
// Shrinks d
end
// Maintains the invariant
// DOESN'T CHANGE d
else
d -= 365
y += 1
// Maintains invariant
// Shrinks d
end
end
return [d,y]
end
end
FIX IT!
class 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 [d,y]
end
end
class 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
else if (d == 366)
return [d,y] // UGH UGH UGH UGH UGH UGH UGH UGH UGH UGH UGH UGH UGH UGH UGH UGH UGH UGH UGH UGH UGH UGH UGH UGH UGH UGH UGH UGH UGH UGH UGH UGH UGH UGH UGH UGH UGH UGH UGH UGH
end
else
d -= 365
y += 1
end
end
return [d,y]
end
end
class TimeSetter
def self.convert(d)
y = 1980
while (d > 366) do
if ((y % 400 == 0) || (y % 4 == 0) && (y % 100 != 0))
d -= 366
y += 1
else
d -= 365
y += 1
end
end
return [d,y]
end
end
class 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 [d,y]
end
end
while (d > daysInYear(y)) {
d -= daysInYear(y);
y += 1;
}
return [d,y]
def self.daysInYear(y) {
if ((y % 400 == 0) || (y % 4 == 0) && (y % 100 != 0)) {
return 366;
}
else {
return 365;
}
}
"I would like to discuss the idea of global surveillance and where to draw the line. It's a grey area for me and I'd like to get more opinions on it."