Skip to content

Commit dd67ea2

Browse files
committed
Merge remote-tracking branch 'rpottsoh/updateMatrix' (#350)
2 parents f5e8c2d + ebd6a4d commit dd67ea2

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

exercises/matrix/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ So given a string with embedded newlines like:
1414
representing this matrix:
1515

1616
```text
17-
0 1 2
17+
1 2 3
1818
|---------
19-
0 | 9 8 7
20-
1 | 5 3 2
21-
2 | 6 6 7
19+
1 | 9 8 7
20+
2 | 5 3 2
21+
3 | 6 6 7
2222
```
2323

2424
your code should be able to spit out:

exercises/matrix/uMatrixExample.pas

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function TMatrix.Column(AInd: integer): TArray<integer>;
2222
begin
2323
SetLength(Result, Length(FMat));
2424
for i := Low(FMat) to High(FMat) do
25-
Result[i] := FMat[i, AInd];
25+
Result[i] := FMat[i, AInd - 1];
2626
end;
2727

2828
constructor TMatrix.Create(AMatr: string);
@@ -42,7 +42,7 @@ constructor TMatrix.Create(AMatr: string);
4242

4343
function TMatrix.Row(AInd: integer): TArray<integer>;
4444
begin
45-
Result := FMat[AInd];
45+
Result := FMat[AInd - 1];
4646
end;
4747

4848
end.

exercises/matrix/uMatrixTest.pas

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ interface
66
DUnitX.TestFramework, System.Generics.Collections;
77

88
const
9-
CanonicalVersion = '1.0.0';
9+
CanonicalVersion = '1.1.0';
1010

1111
type
1212

@@ -18,6 +18,7 @@ TMatrixTest = class(TObject)
1818
public
1919
[Setup]
2020
procedure Setup;
21+
2122
[TearDown]
2223
procedure TearDown;
2324

@@ -66,7 +67,7 @@ procedure TMatrixTest.can_extract_column;
6667
ExpectedRow.AddRange([3, 6, 9]);
6768
Expected := ExpectedRow.ToArray;
6869
CUT := TMatrix.Create('1 2 3\n4 5 6\n7 8 9');
69-
Actual := CUT.column(2);
70+
Actual := CUT.column(3);
7071
CompareArrays(Expected, Actual);
7172
end;
7273

@@ -79,7 +80,7 @@ procedure TMatrixTest.can_extract_column_from_non_square_matrix;
7980
ExpectedRow.AddRange([3, 6, 9, 6]);
8081
Expected := ExpectedRow.ToArray;
8182
CUT := TMatrix.Create('1 2 3\n4 5 6\n7 8 9\n8 7 6');
82-
Actual := CUT.column(2);
83+
Actual := CUT.column(3);
8384
CompareArrays(Expected, Actual);
8485
end;
8586

@@ -92,7 +93,7 @@ procedure TMatrixTest.can_extract_row;
9293
ExpectedRow.AddRange([3, 4]);
9394
Expected := ExpectedRow.ToArray;
9495
CUT := TMatrix.Create('1 2\n3 4');
95-
Actual := CUT.Row(1);
96+
Actual := CUT.Row(2);
9697
CompareArrays(Expected, Actual);
9798
end;
9899

@@ -105,7 +106,7 @@ procedure TMatrixTest.can_extract_row_from_non_square_matrix;
105106
ExpectedRow.AddRange([7, 8, 9]);
106107
Expected := ExpectedRow.ToArray;
107108
CUT := TMatrix.Create('1 2 3\n4 5 6\n7 8 9\n8 7 6');
108-
Actual := CUT.Row(2);
109+
Actual := CUT.Row(3);
109110
CompareArrays(Expected, Actual);
110111
end;
111112

@@ -118,7 +119,7 @@ procedure TMatrixTest.extract_column_from_one_number_matrix;
118119
ExpectedRow.AddRange([1]);
119120
Expected := ExpectedRow.ToArray;
120121
CUT := TMatrix.Create('1');
121-
Actual := CUT.column(0);
122+
Actual := CUT.column(1);
122123
CompareArrays(Expected, Actual);
123124
end;
124125

@@ -131,7 +132,7 @@ procedure TMatrixTest.extract_column_where_numbers_have_different_widths;
131132
ExpectedRow.AddRange([1903, 3, 4]);
132133
Expected := ExpectedRow.ToArray;
133134
CUT := TMatrix.Create('89 1903 3\n18 3 1\n9 4 800');
134-
Actual := CUT.column(1);
135+
Actual := CUT.column(2);
135136
CompareArrays(Expected, Actual);
136137
end;
137138

@@ -144,7 +145,7 @@ procedure TMatrixTest.extract_row_from_one_number_matrix;
144145
ExpectedRow.AddRange([1]);
145146
Expected := ExpectedRow.ToArray;
146147
CUT := TMatrix.Create('1');
147-
Actual := CUT.Row(0);
148+
Actual := CUT.Row(1);
148149
CompareArrays(Expected, Actual);
149150
end;
150151

@@ -157,7 +158,7 @@ procedure TMatrixTest.extract_row_where_numbers_have_different_widths;
157158
ExpectedRow.AddRange([10, 20]);
158159
Expected := ExpectedRow.ToArray;
159160
CUT := TMatrix.Create('1 2\n10 20');
160-
Actual := CUT.Row(1);
161+
Actual := CUT.Row(2);
161162
CompareArrays(Expected, Actual);
162163
end;
163164

0 commit comments

Comments
 (0)