Skip to content

Commit

Permalink
exercises(grains): remove test for negative input
Browse files Browse the repository at this point in the history
  • Loading branch information
ee7 committed Mar 3, 2023
1 parent e3f88ce commit 718b96a
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 10 deletions.
3 changes: 3 additions & 0 deletions exercises/practice/grains/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"authors": [
"massivelivefun"
],
"contributors": [
"ee7"
],
"files": {
"solution": [
"grains.zig"
Expand Down
6 changes: 3 additions & 3 deletions exercises/practice/grains/.meta/example.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ pub const ChessboardError = error{IndexOutOfBounds};

const number_of_chess_squares = 64;

pub fn square(index: isize) ChessboardError!u64 {
if (index > number_of_chess_squares or index <= 0) {
pub fn square(index: usize) ChessboardError!u64 {
if (index > number_of_chess_squares or index == 0) {
return ChessboardError.IndexOutOfBounds;
}
return @as(u64, 1) << @truncate(u6, @bitCast(usize, index) - 1);
return @as(u64, 1) << @truncate(u6, index - 1);
}

pub fn total() u64 {
Expand Down
1 change: 1 addition & 0 deletions exercises/practice/grains/.meta/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ description = "returns the number of grains on the square -> square 0 raises an

[61974483-eeb2-465e-be54-ca5dde366453]
description = "returns the number of grains on the square -> negative square raises an exception"
include = false

[a95e4374-f32c-45a7-a10d-ffec475c012f]
description = "returns the number of grains on the square -> square greater than 64 raises an exception"
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/grains/grains.zig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub fn square(index: isize) ChessboardError!u64 {
pub fn square(index: usize) ChessboardError!u64 {
_ = index;
@compileError("please implement the square function");
}
Expand Down
6 changes: 0 additions & 6 deletions exercises/practice/grains/test_grains.zig
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@ test "square 0 produces an error" {
try testing.expectError(expected, actual);
}

test "negative square produces an error" {
const expected = ChessboardError.IndexOutOfBounds;
const actual = comptime grains.square(-1);
try testing.expectError(expected, actual);
}

test "square greater than 64 produces an error" {
const expected = ChessboardError.IndexOutOfBounds;
const actual = comptime grains.square(65);
Expand Down

0 comments on commit 718b96a

Please sign in to comment.