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
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Instructions append

## Constraints

You may assume that each puzzle has at least 2 rows and at least 2 columns.
126 changes: 126 additions & 0 deletions exercises/practice/piecing-it-together/.meta/supplements.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,132 @@
"aspectRatio": 1.6180257510729614,
"format": "landscape"
}
},
{
"description": "portrait puzzle with 8 border pieces",
"property": "jigsawData",
"input": {
"border": 8,
"format": "portrait"
},
"expected": {
"pieces": 8,
"border": 8,
"inside": 0,
"rows": 4,
"columns": 2,
"aspectRatio": 0.5,
"format": "portrait"
}
},
{
"description": "landscape puzzle with 8 border pieces",
"property": "jigsawData",
"input": {
"border": 8,
"format": "landscape"
},
"expected": {
"pieces": 8,
"border": 8,
"inside": 0,
"rows": 2,
"columns": 4,
"aspectRatio": 2.0,
"format": "landscape"
}
},
{
"description": "puzzle with no inside pieces and aspect ratio 5",
"property": "jigsawData",
"input": {
"inside": 0,
"aspectRatio": 5.0
},
"expected": {
"pieces": 20,
"border": 20,
"inside": 0,
"rows": 2,
"columns": 10,
"aspectRatio": 5.0,
"format": "landscape"
}
},
{
"description": "puzzle with no inside pieces and aspect ratio 0.2",
"property": "jigsawData",
"input": {
"inside": 0,
"aspectRatio": 0.2
},
"expected": {
"pieces": 20,
"border": 20,
"inside": 0,
"rows": 10,
"columns": 2,
"aspectRatio": 0.2,
"format": "portrait"
}
},
{
"description": "puzzle with 87 rows and 94/87 aspect ratio",
"property": "jigsawData",
"input": {
"rows": 87,
"aspectRatio": 1.0804597701149425
},
"expected": {
"pieces": 8178,
"border": 358,
"inside": 7820,
"rows": 87,
"columns": 94,
"aspectRatio": 1.0804597701149425,
"format": "landscape"
}
},
{
"description": "puzzle with 94 columns and 94/87 aspect ratio",
"property": "jigsawData",
"input": {
"columns": 94,
"aspectRatio": 1.0804597701149425
},
"expected": {
"pieces": 8178,
"border": 358,
"inside": 7820,
"rows": 87,
"columns": 94,
"aspectRatio": 1.0804597701149425,
"format": "landscape"
}
},
{
"description": "portrait puzzle with no inside pieces and aspect ratio 1",
"property": "jigsawData",
"input": {
"inside": 0,
"aspectRatio": 1.0,
"format": "portrait"
},
"expected": {
"error": "Contradictory data"
}
},
{
"description": "landscape puzzle with no inside pieces and aspect ratio 1",
"property": "jigsawData",
"input": {
"inside": 0,
"aspectRatio": 1.0,
"format": "landscape"
},
"expected": {
"error": "Contradictory data"
}
}
]
}
128 changes: 128 additions & 0 deletions exercises/practice/piecing-it-together/test_piecing_it_together.zig
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,131 @@ test "very large landscape" {
const actual = try jigsawData(puzzle);
try testing.expectEqual(expected, actual);
}

test "portrait puzzle with 8 border pieces" {
const puzzle = PartialInformation{
.border = 8,
.format = .portrait,
};
const expected = FullInformation{
.pieces = 8,
.border = 8,
.inside = 0,
.rows = 4,
.columns = 2,
.aspectRatio = 0.5,
.format = .portrait,
};
const actual = try jigsawData(puzzle);
try testing.expectEqual(expected, actual);
}

test "landscape puzzle with 8 border pieces" {
const puzzle = PartialInformation{
.border = 8,
.format = .landscape,
};
const expected = FullInformation{
.pieces = 8,
.border = 8,
.inside = 0,
.rows = 2,
.columns = 4,
.aspectRatio = 2.0,
.format = .landscape,
};
const actual = try jigsawData(puzzle);
try testing.expectEqual(expected, actual);
}

test "puzzle with no inside pieces and aspect ratio 5" {
const puzzle = PartialInformation{
.inside = 0,
.aspectRatio = 5.0,
};
const expected = FullInformation{
.pieces = 20,
.border = 20,
.inside = 0,
.rows = 2,
.columns = 10,
.aspectRatio = 5.0,
.format = .landscape,
};
const actual = try jigsawData(puzzle);
try testing.expectEqual(expected, actual);
}

test "puzzle with no inside pieces and aspect ratio 0.2" {
const puzzle = PartialInformation{
.inside = 0,
.aspectRatio = 0.2,
};
const expected = FullInformation{
.pieces = 20,
.border = 20,
.inside = 0,
.rows = 10,
.columns = 2,
.aspectRatio = 0.2,
.format = .portrait,
};
const actual = try jigsawData(puzzle);
try testing.expectEqual(expected, actual);
}

test "puzzle with 87 rows and 94/87 aspect ratio" {
const puzzle = PartialInformation{
.rows = 87,
.aspectRatio = 1.0804597701149425,
};
const expected = FullInformation{
.pieces = 8178,
.border = 358,
.inside = 7820,
.rows = 87,
.columns = 94,
.aspectRatio = 1.0804597701149425,
.format = .landscape,
};
const actual = try jigsawData(puzzle);
try testing.expectEqual(expected, actual);
}

test "puzzle with 94 columns and 94/87 aspect ratio" {
const puzzle = PartialInformation{
.columns = 94,
.aspectRatio = 1.0804597701149425,
};
const expected = FullInformation{
.pieces = 8178,
.border = 358,
.inside = 7820,
.rows = 87,
.columns = 94,
.aspectRatio = 1.0804597701149425,
.format = .landscape,
};
const actual = try jigsawData(puzzle);
try testing.expectEqual(expected, actual);
}

test "portrait puzzle with no inside pieces and aspect ratio 1" {
const puzzle = PartialInformation{
.inside = 0,
.aspectRatio = 1.0,
.format = .portrait,
};
const actual = jigsawData(puzzle);
try testing.expectError(PuzzleError.ContradictoryData, actual);
}

test "landscape puzzle with no inside pieces and aspect ratio 1" {
const puzzle = PartialInformation{
.inside = 0,
.aspectRatio = 1.0,
.format = .landscape,
};
const actual = jigsawData(puzzle);
try testing.expectError(PuzzleError.ContradictoryData, actual);
}
Loading