Skip to content

Commit 290e7f3

Browse files
authored
exercises(grains): remove test for negative input (#210)
1 parent de5aff6 commit 290e7f3

5 files changed

Lines changed: 8 additions & 10 deletions

File tree

exercises/practice/grains/.meta/config.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
"authors": [
33
"massivelivefun"
44
],
5+
"contributors": [
6+
"ee7"
7+
],
58
"files": {
69
"solution": [
710
"grains.zig"

exercises/practice/grains/.meta/example.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ pub const ChessboardError = error{IndexOutOfBounds};
55

66
const number_of_chess_squares = 64;
77

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

1515
pub fn total() u64 {

exercises/practice/grains/.meta/tests.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ description = "returns the number of grains on the square -> square 0 raises an
3535

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

3940
[a95e4374-f32c-45a7-a10d-ffec475c012f]
4041
description = "returns the number of grains on the square -> square greater than 64 raises an exception"

exercises/practice/grains/grains.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pub fn square(index: isize) ChessboardError!u64 {
1+
pub fn square(index: usize) ChessboardError!u64 {
22
_ = index;
33
@compileError("please implement the square function");
44
}

exercises/practice/grains/test_grains.zig

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,6 @@ test "square 0 produces an error" {
5252
try testing.expectError(expected, actual);
5353
}
5454

55-
test "negative square produces an error" {
56-
const expected = ChessboardError.IndexOutOfBounds;
57-
const actual = comptime grains.square(-1);
58-
try testing.expectError(expected, actual);
59-
}
60-
6155
test "square greater than 64 produces an error" {
6256
const expected = ChessboardError.IndexOutOfBounds;
6357
const actual = comptime grains.square(65);

0 commit comments

Comments
 (0)