Normalized exercise output, answers (#41)

1. All exercises should print a trailing \n
2. The build script should always show you _exactly_ what it's looking
   for when you get it wrong. Therefore, .output should be set to the
   exact expected output.
pull/2/head
Dave Gauer 4 years ago
parent 8bb916d7de
commit cc01013921

@ -73,12 +73,12 @@ const exercises = [_]Exercise{
}, },
.{ .{
.main_file = "007_strings2.zig", .main_file = "007_strings2.zig",
.output = "Ziggy", .output = "Ziggy played guitar\nJamming good with Andrew Kelley\nAnd the Spiders from Mars",
.hint = "Please fix the lyrics!", .hint = "Please fix the lyrics!",
}, },
.{ .{
.main_file = "008_quiz.zig", .main_file = "008_quiz.zig",
.output = "Program in Zig", .output = "Program in Zig!",
.hint = "See if you can fix the program!", .hint = "See if you can fix the program!",
}, },
.{ .{
@ -87,16 +87,16 @@ const exercises = [_]Exercise{
}, },
.{ .{
.main_file = "010_if2.zig", .main_file = "010_if2.zig",
.output = "price is $17", .output = "With the discount, the price is $17.",
}, },
.{ .{
.main_file = "011_while.zig", .main_file = "011_while.zig",
.output = "n=1024", .output = "2 4 8 16 32 64 128 256 512 n=1024",
.hint = "You probably want a 'less than' condition.", .hint = "You probably want a 'less than' condition.",
}, },
.{ .{
.main_file = "012_while2.zig", .main_file = "012_while2.zig",
.output = "n=1024", .output = "2 4 8 16 32 64 128 256 512 n=1024",
.hint = "It might help to look back at the previous exercise.", .hint = "It might help to look back at the previous exercise.",
}, },
.{ .{
@ -117,12 +117,12 @@ const exercises = [_]Exercise{
}, },
.{ .{
.main_file = "017_quiz2.zig", .main_file = "017_quiz2.zig",
.output = "8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16", .output = "1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16,",
.hint = "This is a famous game!", .hint = "This is a famous game!",
}, },
.{ .{
.main_file = "018_functions.zig", .main_file = "018_functions.zig",
.output = "Question: 42", .output = "Answer to the Ultimate Question: 42",
.hint = "Can you help write the function?", .hint = "Can you help write the function?",
}, },
.{ .{
@ -158,7 +158,7 @@ const exercises = [_]Exercise{
}, },
.{ .{
.main_file = "026_hello2.zig", .main_file = "026_hello2.zig",
.output = "Hello world", .output = "Hello world!",
.hint = "Try using a try!", .hint = "Try using a try!",
.check_stdout = true, .check_stdout = true,
}, },
@ -204,7 +204,7 @@ const exercises = [_]Exercise{
}, },
.{ .{
.main_file = "036_enums2.zig", .main_file = "036_enums2.zig",
.output = "#0000ff", .output = "<p>\n <span style=\"color: #ff0000\">Red</span>\n <span style=\"color: #00ff00\">Green</span>\n <span style=\"color: #0000ff\">Blue</span>\n</p>",
.hint = "I'm feeling blue about this.", .hint = "I'm feeling blue about this.",
}, },
.{ .{
@ -213,7 +213,7 @@ const exercises = [_]Exercise{
}, },
.{ .{
.main_file = "038_structs2.zig", .main_file = "038_structs2.zig",
.output = "Character 2 - G:10 H:100 XP:20", .output = "Character 1 - G:20 H:100 XP:10\nCharacter 2 - G:10 H:100 XP:20",
}, },
.{ .{
.main_file = "039_pointers.zig", .main_file = "039_pointers.zig",

@ -25,5 +25,5 @@ pub fn main() void {
// an error. Can you set the type correctly above? // an error. Can you set the type correctly above?
my_number = MyNumberError.TooSmall; my_number = MyNumberError.TooSmall;
std.debug.print("I compiled!", .{}); std.debug.print("I compiled!\n", .{});
} }

@ -14,7 +14,7 @@ pub fn main() void {
var a: u32 = addTwenty(44) catch 22; var a: u32 = addTwenty(44) catch 22;
var b: u32 = addTwenty(4) ??? 22; var b: u32 = addTwenty(4) ??? 22;
std.debug.print("a={}, b={}", .{ a, b }); std.debug.print("a={}, b={}\n", .{ a, b });
} }
// Please provide the return type from this function. // Please provide the return type from this function.

@ -25,7 +25,7 @@ pub fn main() void {
var b: u32 = makeJustRight(14) catch 0; var b: u32 = makeJustRight(14) catch 0;
var c: u32 = makeJustRight(4) catch 0; var c: u32 = makeJustRight(4) catch 0;
std.debug.print("a={}, b={}, c={}", .{ a, b, c }); std.debug.print("a={}, b={}, c={}\n", .{ a, b, c });
} }
// In this silly example we've split the responsibility of making // In this silly example we've split the responsibility of making

@ -19,7 +19,7 @@ pub fn main() void {
var b: u32 = addFive(14) catch 0; var b: u32 = addFive(14) catch 0;
var c: u32 = addFive(4) catch 0; var c: u32 = addFive(4) catch 0;
std.debug.print("a={}, b={}, c={}", .{ a, b, c }); std.debug.print("a={}, b={}, c={}\n", .{ a, b, c });
} }
fn addFive(n: u32) MyNumberError!u32 { fn addFive(n: u32) MyNumberError!u32 {

@ -53,6 +53,7 @@ pub fn main() void {
\\ <span style="color: #{x:0>6}">Green</span> \\ <span style="color: #{x:0>6}">Green</span>
\\ <span style="color: #{}">Blue</span> \\ <span style="color: #{}">Blue</span>
\\</p> \\</p>
\\
, .{ , .{
@enumToInt(Color.red), @enumToInt(Color.red),
@enumToInt(Color.green), @enumToInt(Color.green),

@ -52,7 +52,7 @@ pub fn main() void {
// Ouch! Glorp takes a punch! // Ouch! Glorp takes a punch!
glorp_the_wise.health -= 10; glorp_the_wise.health -= 10;
std.debug.print("Your wizard has {} health and {} gold.", .{ std.debug.print("Your wizard has {} health and {} gold.\n", .{
glorp_the_wise.health, glorp_the_wise.health,
glorp_the_wise.gold, glorp_the_wise.gold,
}); });

@ -73,7 +73,7 @@ fn printCharacter(c: *Character) void {
.warrior => "Warrior", .warrior => "Warrior",
}; };
std.debug.print("{s} (G:{} H:{} XP:{})", .{ std.debug.print("{s} (G:{} H:{} XP:{})\n", .{
class_name, class_name,
c.gold, c.gold,
c.health, c.health,

Loading…
Cancel
Save