Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions exercises/practice/food-chain/.docs/instructions.append.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Instructions append

## Detect invalid input

Use [std.debug.assert][assert] or return an [error][error].

[error]: https://ziglang.org/documentation/master/#Errors
[assert]: https://ziglang.org/documentation/master/std/#std.debug.assert
5 changes: 4 additions & 1 deletion exercises/practice/food-chain/.meta/example.zig
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ fn appendString(buffer: []u8, offset: *usize, str: []const u8) void {
offset.* += str.len;
}

pub fn recite(buffer: []u8, start_verse: u32, end_verse: u32) []const u8 {
pub fn recite(buffer: []u8, start_verse: u32, end_verse: u32) ![]const u8 {
std.debug.assert(start_verse >= 1);
std.debug.assert(end_verse >= start_verse);
std.debug.assert(end_verse <= 8);
var offset: usize = 0;

for (start_verse..(end_verse + 1)) |verse| {
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/food-chain/food_chain.zig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub fn recite(buffer: []u8, start_verse: u32, end_verse: u32) []const u8 {
pub fn recite(buffer: []u8, start_verse: u32, end_verse: u32) ![]const u8 {
_ = buffer;
_ = start_verse;
_ = end_verse;
Expand Down
20 changes: 10 additions & 10 deletions exercises/practice/food-chain/test_food_chain.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ test "fly" {
\\I know an old lady who swallowed a fly.
\\I don't know why she swallowed the fly. Perhaps she'll die.
;
const actual = food_chain.recite(&buffer, 1, 1);
const actual = try food_chain.recite(&buffer, 1, 1);
try testing.expectEqualStrings(expected, actual);
}

Expand All @@ -23,7 +23,7 @@ test "spider" {
\\She swallowed the spider to catch the fly.
\\I don't know why she swallowed the fly. Perhaps she'll die.
;
const actual = food_chain.recite(&buffer, 2, 2);
const actual = try food_chain.recite(&buffer, 2, 2);
try testing.expectEqualStrings(expected, actual);
}

Expand All @@ -37,7 +37,7 @@ test "bird" {
\\She swallowed the spider to catch the fly.
\\I don't know why she swallowed the fly. Perhaps she'll die.
;
const actual = food_chain.recite(&buffer, 3, 3);
const actual = try food_chain.recite(&buffer, 3, 3);
try testing.expectEqualStrings(expected, actual);
}

Expand All @@ -52,7 +52,7 @@ test "cat" {
\\She swallowed the spider to catch the fly.
\\I don't know why she swallowed the fly. Perhaps she'll die.
;
const actual = food_chain.recite(&buffer, 4, 4);
const actual = try food_chain.recite(&buffer, 4, 4);
try testing.expectEqualStrings(expected, actual);
}

Expand All @@ -68,7 +68,7 @@ test "dog" {
\\She swallowed the spider to catch the fly.
\\I don't know why she swallowed the fly. Perhaps she'll die.
;
const actual = food_chain.recite(&buffer, 5, 5);
const actual = try food_chain.recite(&buffer, 5, 5);
try testing.expectEqualStrings(expected, actual);
}

Expand All @@ -85,7 +85,7 @@ test "goat" {
\\She swallowed the spider to catch the fly.
\\I don't know why she swallowed the fly. Perhaps she'll die.
;
const actual = food_chain.recite(&buffer, 6, 6);
const actual = try food_chain.recite(&buffer, 6, 6);
try testing.expectEqualStrings(expected, actual);
}

Expand All @@ -103,7 +103,7 @@ test "cow" {
\\She swallowed the spider to catch the fly.
\\I don't know why she swallowed the fly. Perhaps she'll die.
;
const actual = food_chain.recite(&buffer, 7, 7);
const actual = try food_chain.recite(&buffer, 7, 7);
try testing.expectEqualStrings(expected, actual);
}

Expand All @@ -114,7 +114,7 @@ test "horse" {
\\I know an old lady who swallowed a horse.
\\She's dead, of course!
;
const actual = food_chain.recite(&buffer, 8, 8);
const actual = try food_chain.recite(&buffer, 8, 8);
try testing.expectEqualStrings(expected, actual);
}

Expand All @@ -136,7 +136,7 @@ test "multiple verses" {
\\She swallowed the spider to catch the fly.
\\I don't know why she swallowed the fly. Perhaps she'll die.
;
const actual = food_chain.recite(&buffer, 1, 3);
const actual = try food_chain.recite(&buffer, 1, 3);
try testing.expectEqualStrings(expected, actual);
}

Expand Down Expand Up @@ -195,6 +195,6 @@ test "full song" {
\\I know an old lady who swallowed a horse.
\\She's dead, of course!
;
const actual = food_chain.recite(&buffer, 1, 8);
const actual = try food_chain.recite(&buffer, 1, 8);
try testing.expectEqualStrings(expected, actual);
}
8 changes: 8 additions & 0 deletions exercises/practice/house/.docs/instructions.append.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Instructions append

## Detect invalid input

Use [std.debug.assert][assert] or return an [error][error].

[error]: https://ziglang.org/documentation/master/#Errors
[assert]: https://ziglang.org/documentation/master/std/#std.debug.assert
4 changes: 3 additions & 1 deletion exercises/practice/house/.meta/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"authors": [],
"authors": [
"keiravillekode"
],
"files": {
"solution": [
"house.zig"
Expand Down
5 changes: 4 additions & 1 deletion exercises/practice/house/.meta/example.zig
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ fn appendString(buffer: []u8, offset: *usize, str: []const u8) void {
offset.* += str.len;
}

pub fn recite(buffer: []u8, start_verse: u32, end_verse: u32) []const u8 {
pub fn recite(buffer: []u8, start_verse: u32, end_verse: u32) ![]const u8 {
std.debug.assert(start_verse >= 1);
std.debug.assert(end_verse >= start_verse);
std.debug.assert(end_verse <= 12);
var offset: usize = 0;

for (start_verse..(end_verse + 1)) |verse| {
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/house/house.zig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub fn recite(buffer: []u8, start_verse: u32, end_verse: u32) []const u8 {
pub fn recite(buffer: []u8, start_verse: u32, end_verse: u32) ![]const u8 {
_ = buffer;
_ = start_verse;
_ = end_verse;
Expand Down
28 changes: 14 additions & 14 deletions exercises/practice/house/test_house.zig
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ test "verse one - the house that jack built" {
const expected: []const u8 =
\\This is the house that Jack built.
;
const actual = house.recite(&buffer, 1, 1);
const actual = try house.recite(&buffer, 1, 1);
try testing.expectEqualStrings(expected, actual);
}

Expand All @@ -19,7 +19,7 @@ test "verse two - the malt that lay" {
const expected: []const u8 =
\\This is the malt that lay in the house that Jack built.
;
const actual = house.recite(&buffer, 2, 2);
const actual = try house.recite(&buffer, 2, 2);
try testing.expectEqualStrings(expected, actual);
}

Expand All @@ -29,7 +29,7 @@ test "verse three - the rat that ate" {
const expected: []const u8 =
\\This is the rat that ate the malt that lay in the house that Jack built.
;
const actual = house.recite(&buffer, 3, 3);
const actual = try house.recite(&buffer, 3, 3);
try testing.expectEqualStrings(expected, actual);
}

Expand All @@ -39,7 +39,7 @@ test "verse four - the cat that killed" {
const expected: []const u8 =
\\This is the cat that killed the rat that ate the malt that lay in the house that Jack built.
;
const actual = house.recite(&buffer, 4, 4);
const actual = try house.recite(&buffer, 4, 4);
try testing.expectEqualStrings(expected, actual);
}

Expand All @@ -49,7 +49,7 @@ test "verse five - the dog that worried" {
const expected: []const u8 =
\\This is the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built.
;
const actual = house.recite(&buffer, 5, 5);
const actual = try house.recite(&buffer, 5, 5);
try testing.expectEqualStrings(expected, actual);
}

Expand All @@ -59,7 +59,7 @@ test "verse six - the cow with the crumpled horn" {
const expected: []const u8 =
\\This is the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built.
;
const actual = house.recite(&buffer, 6, 6);
const actual = try house.recite(&buffer, 6, 6);
try testing.expectEqualStrings(expected, actual);
}

Expand All @@ -69,7 +69,7 @@ test "verse seven - the maiden all forlorn" {
const expected: []const u8 =
\\This is the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built.
;
const actual = house.recite(&buffer, 7, 7);
const actual = try house.recite(&buffer, 7, 7);
try testing.expectEqualStrings(expected, actual);
}

Expand All @@ -79,7 +79,7 @@ test "verse eight - the man all tattered and torn" {
const expected: []const u8 =
\\This is the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built.
;
const actual = house.recite(&buffer, 8, 8);
const actual = try house.recite(&buffer, 8, 8);
try testing.expectEqualStrings(expected, actual);
}

Expand All @@ -89,7 +89,7 @@ test "verse nine - the priest all shaven and shorn" {
const expected: []const u8 =
\\This is the priest all shaven and shorn that married the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built.
;
const actual = house.recite(&buffer, 9, 9);
const actual = try house.recite(&buffer, 9, 9);
try testing.expectEqualStrings(expected, actual);
}

Expand All @@ -99,7 +99,7 @@ test "verse 10 - the rooster that crowed in the morn" {
const expected: []const u8 =
\\This is the rooster that crowed in the morn that woke the priest all shaven and shorn that married the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built.
;
const actual = house.recite(&buffer, 10, 10);
const actual = try house.recite(&buffer, 10, 10);
try testing.expectEqualStrings(expected, actual);
}

Expand All @@ -109,7 +109,7 @@ test "verse 11 - the farmer sowing his corn" {
const expected: []const u8 =
\\This is the farmer sowing his corn that kept the rooster that crowed in the morn that woke the priest all shaven and shorn that married the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built.
;
const actual = house.recite(&buffer, 11, 11);
const actual = try house.recite(&buffer, 11, 11);
try testing.expectEqualStrings(expected, actual);
}

Expand All @@ -119,7 +119,7 @@ test "verse 12 - the horse and the hound and the horn" {
const expected: []const u8 =
\\This is the horse and the hound and the horn that belonged to the farmer sowing his corn that kept the rooster that crowed in the morn that woke the priest all shaven and shorn that married the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built.
;
const actual = house.recite(&buffer, 12, 12);
const actual = try house.recite(&buffer, 12, 12);
try testing.expectEqualStrings(expected, actual);
}

Expand All @@ -133,7 +133,7 @@ test "multiple verses" {
\\This is the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built.
\\This is the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built.
;
const actual = house.recite(&buffer, 4, 8);
const actual = try house.recite(&buffer, 4, 8);
try testing.expectEqualStrings(expected, actual);
}

Expand All @@ -154,6 +154,6 @@ test "full rhyme" {
\\This is the farmer sowing his corn that kept the rooster that crowed in the morn that woke the priest all shaven and shorn that married the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built.
\\This is the horse and the hound and the horn that belonged to the farmer sowing his corn that kept the rooster that crowed in the morn that woke the priest all shaven and shorn that married the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built.
;
const actual = house.recite(&buffer, 1, 12);
const actual = try house.recite(&buffer, 1, 12);
try testing.expectEqualStrings(expected, actual);
}
8 changes: 8 additions & 0 deletions exercises/practice/twelve-days/.docs/instructions.append.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Instructions append

## Detect invalid input

Use [std.debug.assert][assert] or return an [error][error].

[error]: https://ziglang.org/documentation/master/#Errors
[assert]: https://ziglang.org/documentation/master/std/#std.debug.assert
5 changes: 4 additions & 1 deletion exercises/practice/twelve-days/.meta/example.zig
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ fn appendString(buffer: []u8, offset: *usize, str: []const u8) void {
offset.* += str.len;
}

pub fn recite(buffer: []u8, start_verse: u32, end_verse: u32) []const u8 {
pub fn recite(buffer: []u8, start_verse: u32, end_verse: u32) ![]const u8 {
std.debug.assert(start_verse >= 1);
std.debug.assert(end_verse >= start_verse);
std.debug.assert(end_verse <= 12);
var offset: usize = 0;

for (start_verse..(end_verse + 1)) |verse| {
Expand Down
Loading