Skip to content

Commit 9246071

Browse files
authored
Merge pull request #183 from rpottsoh/reverseString
reverse-string: add exercise to track
2 parents dca367d + 8c2f364 commit 9246071

File tree

5 files changed

+191
-0
lines changed

5 files changed

+191
-0
lines changed

config.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@
2222
],
2323
"uuid": "60eb0882-495d-45f4-8d38-5b10d8851cf6"
2424
},
25+
{
26+
"core": false,
27+
"difficulty": 1,
28+
"slug": "reverse-string",
29+
"topics": [
30+
"strings"
31+
],
32+
"unlocked_by": null,
33+
"uuid": "8bdf3796-592c-48f1-b2ef-8e4deb40cc37"
34+
},
2535
{
2636
"core": false,
2737
"difficulty": 1,

exercises/reverse-string/README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# reverse-string
2+
3+
Reverse a string
4+
5+
For example:
6+
input: "cool"
7+
output: "looc"
8+
9+
## Testing
10+
11+
In order to run the tests for this track, you will need to install
12+
DUnitX. Please see the [installation](http://www.exercism.io/languages/delphi/installing) instructions for more information.
13+
14+
### Loading Exercises into Delphi
15+
16+
If Delphi is properly installed, and `*.dpr` file types have been associated with Delphi, then double clicking the supplied `*.dpr` file will start Delphi and load the exercise/project. `control + F9` is the keyboard shortcut to compile the project or pressing `F9` will compile and run the project.
17+
18+
Alternatively you may opt to start Delphi and load your project via. the `File` drop down menu.
19+
20+
### When Questions Come Up
21+
We monitor the [Pascal-Delphi](https://gitter.im/exercism/Pascal-Delphi) support room on [gitter.im](https://gitter.im) to help you with any questions that might arise.
22+
23+
### Submitting Exercises
24+
25+
Note that, when trying to submit an exercise, make sure the exercise file you're submitting is in the `exercism/delphi/<exerciseName>` directory.
26+
27+
For example, if you're submitting `ubob.pas` for the Bob exercise, the submit command would be something like `exercism submit <path_to_exercism_dir>/delphi/bob/ubob.pas`.
28+
29+
## Source
30+
31+
Introductory challenge to reverse an input string [https://medium.freecodecamp.org/how-to-reverse-a-string-in-javascript-in-3-different-ways-75e4763c68cb](https://medium.freecodecamp.org/how-to-reverse-a-string-in-javascript-in-3-different-ways-75e4763c68cb)
32+
33+
## Submitting Incomplete Solutions
34+
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
program ReverseString;
2+
3+
{$IFNDEF TESTINSIGHT}
4+
{$APPTYPE CONSOLE}
5+
{$ENDIF}{$STRONGLINKTYPES ON}
6+
uses
7+
System.SysUtils,
8+
{$IFDEF TESTINSIGHT}
9+
TestInsight.DUnitX,
10+
{$ENDIF }
11+
DUnitX.Loggers.Console,
12+
DUnitX.Loggers.Xml.NUnit,
13+
DUnitX.TestFramework,
14+
uReverseStringTests in 'uReverseStringTests.pas',
15+
uReverseString in 'uReverseString.pas';
16+
17+
var
18+
runner : ITestRunner;
19+
results : IRunResults;
20+
logger : ITestLogger;
21+
nunitLogger : ITestLogger;
22+
begin
23+
{$IFDEF TESTINSIGHT}
24+
TestInsight.DUnitX.RunRegisteredTests;
25+
exit;
26+
{$ENDIF}
27+
try
28+
//Check command line options, will exit if invalid
29+
TDUnitX.CheckCommandLine;
30+
//Create the test runner
31+
runner := TDUnitX.CreateRunner;
32+
//Tell the runner to use RTTI to find Fixtures
33+
runner.UseRTTI := True;
34+
//tell the runner how we will log things
35+
//Log to the console window
36+
logger := TDUnitXConsoleLogger.Create(true);
37+
runner.AddLogger(logger);
38+
//Generate an NUnit compatible XML File
39+
nunitLogger := TDUnitXXMLNUnitFileLogger.Create(TDUnitX.Options.XMLOutputFile);
40+
runner.AddLogger(nunitLogger);
41+
runner.FailsOnNoAsserts := True; //When true, Assertions must be made during tests;
42+
43+
//Run tests
44+
results := runner.Execute;
45+
if not results.AllPassed then
46+
System.ExitCode := EXIT_ERRORS;
47+
48+
{$IFNDEF CI}
49+
//We don't want this happening when running under CI.
50+
if TDUnitX.Options.ExitBehavior = TDUnitXExitBehavior.Pause then
51+
begin
52+
System.Write('Done.. press <Enter> key to quit.');
53+
System.Readln;
54+
end;
55+
{$ENDIF}
56+
except
57+
on E: Exception do
58+
System.Writeln(E.ClassName, ': ', E.Message);
59+
end;
60+
end.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
unit uReverseString;
2+
3+
interface
4+
5+
function reverse(aInString: string): string;
6+
7+
implementation
8+
9+
function reverse(aInString: string): string;
10+
var
11+
i: integer;
12+
begin
13+
result := '';
14+
for i := Low(aInString) to High(aInString) do
15+
result := aInString[i] + result;
16+
end;
17+
18+
end.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
unit uReverseStringTests;
2+
3+
interface
4+
uses
5+
DUnitX.TestFramework;
6+
7+
const
8+
CanonicalVersion = '1.0.1';
9+
10+
type
11+
12+
[TestFixture]
13+
ReverseStringTest = class(TObject)
14+
public
15+
[Test]
16+
// [Ignore('Comment the "[Ignore]" statement to run the test')]
17+
procedure an_empty_string;
18+
19+
[Test]
20+
[Ignore]
21+
procedure a_word;
22+
23+
[Test]
24+
[Ignore]
25+
procedure a_capitalized_word;
26+
27+
[Test]
28+
[Ignore]
29+
procedure a_sentence_with_punctuation;
30+
31+
[Test]
32+
[Ignore]
33+
procedure a_palindrome;
34+
end;
35+
36+
implementation
37+
uses uReverseString;
38+
39+
40+
{ ReverseStringTest }
41+
42+
procedure ReverseStringTest.an_empty_string;
43+
begin
44+
Assert.AreEqual('', reverse(''));
45+
end;
46+
47+
procedure ReverseStringTest.a_capitalized_word;
48+
begin
49+
Assert.AreEqual('nemaR',reverse('Ramen'));
50+
end;
51+
52+
procedure ReverseStringTest.a_palindrome;
53+
begin
54+
Assert.AreEqual('racecar',reverse('racecar'));
55+
end;
56+
57+
procedure ReverseStringTest.a_sentence_with_punctuation;
58+
begin
59+
Assert.AreEqual('!yrgnuh m''I', reverse('I''m hungry!'));
60+
end;
61+
62+
procedure ReverseStringTest.a_word;
63+
begin
64+
Assert.AreEqual('tobor', reverse('robot'));
65+
end;
66+
67+
initialization
68+
TDUnitX.RegisterTestFixture(ReverseStringTest);
69+
end.

0 commit comments

Comments
 (0)