Skip to content

Hamming: update to v2.3.0 #369

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 8, 2019
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
10 changes: 8 additions & 2 deletions exercises/hamming/uHammingExample.pas
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,18 @@ implementation
uses System.SysUtils;

class function THamming.Distance(strand1, strand2: string): integer;
var i: integer;
begin
if strand1.IsEmpty and not strand2.IsEmpty then
raise EArgumentException.Create('error: left strand must not be empty');

if not strand1.IsEmpty and strand2.IsEmpty then
raise EArgumentException.Create('error: right strand must not be empty');

if strand1.Length <> strand2.Length then
raise EArgumentException.Create('error: left and right strands must be of equal length');

result := 0;
for i := Low(strand1) to High(strand1) do
for var i := Low(strand1) to High(strand1) do
result := result + ord(strand1[i] <> strand2[i]);
end;

Expand Down
32 changes: 30 additions & 2 deletions exercises/hamming/uHammingTests.pas
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ interface
DUnitX.TestFramework;

const
CanonicalVersion = '2.2.0';
CanonicalVersion = '2.3.0';

type
[TestFixture]
HammingTests = class(TObject)
public
[Test]
// [Ignore('Comment the "[Ignore]" statement to run the test')]
// [Ignore('Comment the "[Ignore]" statement to run the test')]
procedure empty_strands;

[Test]
Expand All @@ -38,6 +38,14 @@ HammingTests = class(TObject)
[Test]
[Ignore]
procedure disallow_second_strand_longer;

[Test]
[Ignore]
procedure disallow_left_empty_strand;

[Test]
[Ignore]
procedure disallow_right_empty_strand;
end;

implementation
Expand Down Expand Up @@ -78,6 +86,26 @@ procedure HammingTests.disallow_first_strand_longer;
Assert.WillRaiseWithMessage(MyProc, EArgumentException, 'error: left and right strands must be of equal length');
end;

procedure HammingTests.disallow_left_empty_strand;
var MyProc: TTestLocalMethod;
begin
MyProc := procedure
begin
THamming.Distance('', 'G');
end;
Assert.WillRaiseWithMessage(MyProc, EArgumentException, 'error: left strand must not be empty');
end;

procedure HammingTests.disallow_right_empty_strand;
var MyProc: TTestLocalMethod;
begin
MyProc := procedure
begin
THamming.Distance('G', '');
end;
Assert.WillRaiseWithMessage(MyProc, EArgumentException, 'error: right strand must not be empty');
end;

procedure HammingTests.disallow_second_strand_longer;
var MyProc: TTestLocalMethod;
begin
Expand Down