Skip to content

Commit

Permalink
Changes based on codereview
Browse files Browse the repository at this point in the history
clrInvoice: removed wrong object.free
clrLoadData: removed unnecessary lines
clrPerformance: added necessary create statement
clrPlay: added necessary create statement
clrStatementPrinter: removed unnecessary lines
TestTheatricalPlayers.dpr: removed unnecessary units from 3d-party product
uTestStatementPrinter:
 - removed unittests, that are part of the challange
 - changed the other tests to match the tests in the java-version
 - released objects after using them

removed unnecessary files

updated gitignore
  • Loading branch information
ansgargosling committed Mar 22, 2024
1 parent d6fd803 commit a5e06af
Show file tree
Hide file tree
Showing 11 changed files with 110 additions and 220 deletions.
6 changes: 6 additions & 0 deletions delphi/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,9 @@ unittests/Win32/PLAINDUNITX/dunitx-results.xml
unittests/Win32/TESTINSIGHT/TestInsightSettings.ini
*.log
unittests/Win32/CI/dunitx-results.xml

# DUnit-generated files
dunitx-results.xml

# madExcept-Setting
*.mes
10 changes: 2 additions & 8 deletions delphi/main/clrInvoice.pas
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ TInvoice = class(TObject)
Performances: TPerformances;

constructor Create(ACustomer: string; APerformances: TPerformances);
destructor Destroy; override;
end;

TInvoices = class(TObjectList<TInvoice>)
Expand All @@ -24,15 +23,10 @@ implementation

constructor TInvoice.Create(ACustomer: string; APerformances: TPerformances);
begin
inherited Create;

Customer := ACustomer;
Performances := APerformances;
end;

destructor TInvoice.Destroy;
begin
FreeAndNil(Performances);

inherited;
end;

end.
2 changes: 0 additions & 2 deletions delphi/main/clrLoadData.pas
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ TLoadData = class(TObject)

implementation



class procedure TLoadData.LoadPLays(APLays: TPlays);
var
PlaysJSON: TJSONObject;
Expand Down
2 changes: 2 additions & 0 deletions delphi/main/clrPerformance.pas
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ implementation

constructor TPerformance.Create(APlayId: string; AAudience: Integer);
begin
inherited Create;

PlayId := APlayId;
Audience := AAudience;
end;
Expand Down
2 changes: 2 additions & 0 deletions delphi/main/clrPlay.pas
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ implementation

constructor TPlay.Create(APlayID, AName, AType: string);
begin
inherited Create;

PlayId := APlayID;
Name := AName;
&Type := AType;
Expand Down
1 change: 0 additions & 1 deletion delphi/main/clrStatementPrinter.pas
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,4 @@ class function TStatementPrinter.Print(AInvoice: TInvoice; APlays: TPlays): stri
Result := Result + Format('You earned %d credits'#13#10, [VolumeCredits]);
end;


end.
5 changes: 0 additions & 5 deletions delphi/test/TestTheatricalPlayers.dpr
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ program TestTheatricalPlayers;
{$ENDIF}
{$STRONGLINKTYPES ON}
uses
madExcept,
madLinkDisAsm,
madListHardware,
madListProcesses,
madListModules,
System.SysUtils,
{$IFDEF TESTINSIGHT}
TestInsight.DUnitX,
Expand Down
1 change: 0 additions & 1 deletion delphi/test/TestTheatricalPlayers.dproj
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@
<DCC_RemoteDebug>true</DCC_RemoteDebug>
</PropertyGroup>
<PropertyGroup Condition="'$(Cfg_1_Win32)'!=''">
<DCC_Define>madExcept;$(DCC_Define)</DCC_Define>
<DCC_MapFile>3</DCC_MapFile>
<DCC_RemoteDebug>false</DCC_RemoteDebug>
</PropertyGroup>
Expand Down
20 changes: 0 additions & 20 deletions delphi/test/Win32/Debug/dunitx-results.xml

This file was deleted.

35 changes: 0 additions & 35 deletions delphi/test/Win32/Release/dunitx-results.xml

This file was deleted.

246 changes: 98 additions & 148 deletions delphi/test/uTestStatementPrinter.pas
Original file line number Diff line number Diff line change
@@ -1,148 +1,98 @@
unit uTestStatementPrinter;

interface

uses
System.SysUtils,
DUnitX.TestFramework,
clrInvoice,
clrPlay,
clrPerformance,
clrStatementPrinter;

type
[TestFixture]
TTestStatementPrinter = class
public
[Test]
procedure TestTragedy;

[Test]
procedure TestComedy;

[Test]
procedure TestUnknownPlay;

[Test]
procedure TestMultiplePerformances;
end;

implementation

procedure TTestStatementPrinter.TestTragedy;
var
Actual: string;
Invoice: TInvoice;
Plays: TPlays;
Performances: TPerformances;
const
Expected = '''
Statement for BigCo
Hamlet: $650.00 (55 seats)
Amount owed is $650.00
You earned 25 credits
''';
begin
Performances := TPerformances.Create;
Performances.Add(TPerformance.Create('hamlet', 55));

Invoice := TInvoice.Create('BigCo', Performances);

Plays := TPlays.Create;
Plays.Add(TPlay.Create('hamlet', 'Hamlet', 'tragedy'));

Actual := TStatementPrinter.Print(Invoice, Plays);
Assert.AreEqual(Expected, Actual);
end;

procedure TTestStatementPrinter.TestComedy;
var
Actual: string;
Invoice: TInvoice;
Plays: TPlays;
Performances: TPerformances;
const
Expected = '''
Statement for BigCo
As You Like It: $580.00 (35 seats)
Amount owed is $580.00
You earned 12 credits
''';
begin
Performances := TPerformances.Create;
Performances.Add(TPerformance.Create('as-like', 35));

Invoice := TInvoice.Create('BigCo', Performances);

Plays := TPlays.Create;
Plays.Add(TPlay.Create('as-like', 'As You Like It', 'comedy'));

Actual := TStatementPrinter.Print(Invoice, Plays);
Assert.AreEqual(Expected, Actual);
end;

procedure TTestStatementPrinter.TestUnknownPlay;
var
Actual: string;
Invoice: TInvoice;
Plays: TPlays;
Performances: TPerformances;
const
UnknownPlay = 'unknown-play';
UnknownType = 'unknown-type';
begin
Performances := TPerformances.Create;
Performances.Add(TPerformance.Create(UnknownPlay, 10));

Invoice := TInvoice.Create('BigCo', Performances);

Plays := TPlays.Create;
Plays.Add(TPlay.Create(UnknownPlay, 'Unknown Play', UnknownType));

Assert.WillRaise(
procedure
begin
TStatementPrinter.Print(Invoice, Plays);
end, Exception, 'unknown type: ' + UnknownType
);
end;

procedure TTestStatementPrinter.TestMultiplePerformances;
var
Actual: string;
Invoice: TInvoice;
Plays: TPlays;
Performances: TPerformances;
const
Expected = '''
Statement for BigCo
Hamlet: $650.00 (55 seats)
As You Like It: $580.00 (35 seats)
Othello: $500.00 (40 seats)
Amount owed is $1,730.00
You earned 47 credits
''';
begin
Performances := TPerformances.Create;
Performances.Add(TPerformance.Create('hamlet', 55));
Performances.Add(TPerformance.Create('as-like', 35));
Performances.Add(TPerformance.Create('othello', 40));

Invoice := TInvoice.Create('BigCo', Performances);

Plays := TPlays.Create;
Plays.Add(TPlay.Create('hamlet', 'Hamlet', 'tragedy'));
Plays.Add(TPlay.Create('as-like', 'As You Like It', 'comedy'));
Plays.Add(TPlay.Create('othello', 'Othello', 'tragedy'));

Actual := TStatementPrinter.Print(Invoice, Plays);
Assert.AreEqual(Expected, Actual);
end;

initialization
TDUnitX.RegisterTestFixture(TTestStatementPrinter);

end.

unit uTestStatementPrinter;

interface

uses
System.SysUtils,
DUnitX.TestFramework,
clrInvoice,
clrPlay,
clrPerformance,
clrStatementPrinter;

type
[TestFixture]
TTestStatementPrinter = class
public
[Test]
procedure ExampleStatement;

[Test]
procedure StatementWithNewPlayTypes;
end;

implementation

procedure TTestStatementPrinter.ExampleStatement;
var
Actual: string;
Invoice: TInvoice;
Plays: TPlays;
Performances: TPerformances;
const
Expected = '''
Statement for BigCo
Hamlet: $650.00 (55 seats)
As You Like It: $580.00 (35 seats)
Othello: $500.00 (40 seats)
Amount owed is $1,730.00
You earned 47 credits
''';
begin
Performances := TPerformances.Create;
Plays := TPlays.Create;
Invoice := TInvoice.Create('BigCo', Performances);
try
Plays.Add(TPlay.Create('hamlet', 'Hamlet', 'tragedy'));
Plays.Add(TPlay.Create('as-like', 'As You Like It', 'comedy'));
Plays.Add(TPlay.Create('othello', 'Othello', 'tragedy'));

Performances.Add(TPerformance.Create('hamlet', 55));
Performances.Add(TPerformance.Create('as-like', 35));
Performances.Add(TPerformance.Create('othello', 40));

Actual := TStatementPrinter.Print(Invoice, Plays);
Assert.AreEqual(Expected, Actual);
finally
Invoice.Free;
Plays.Free;
Performances.Free;
end;
end;

procedure TTestStatementPrinter.StatementWithNewPlayTypes;
var
Actual: string;
Invoice: TInvoice;
Plays: TPlays;
Performances: TPerformances;
begin
Performances := TPerformances.Create;
Plays := TPlays.Create;
Invoice := TInvoice.Create('BigCo', Performances);
try
Plays.Add(TPlay.Create('henry-v', 'Henry V', 'history'));
Plays.Add(TPlay.Create('as-like', 'As You Like It', 'pastoral'));

Performances.Add(TPerformance.Create('henry-v', 53));
Performances.Add(TPerformance.Create('as-like', 55));

Assert.WillRaise(
procedure
begin
TStatementPrinter.Print(Invoice, Plays);
end, Exception, 'unknown type: ' + 'henry-v'
);
finally
Invoice.Free;
Plays.Free;
Performances.Free;
end;
end;

initialization
TDUnitX.RegisterTestFixture(TTestStatementPrinter);

end.

0 comments on commit a5e06af

Please sign in to comment.