🎉 Exercism Research is now launched. Help Exercism, help science and have some fun at research.exercism.io 🎉
Avatar of vand3rson

vand3rson's solution

to Reverse String in the Delphi Pascal Track

Published at Jan 22 2021 · 0 comments
Instructions
Test suite
Solution

Reverse a string

For example: input: "cool" output: "looc"

Testing

In order to run the tests for this track, you will need to install DUnitX. Please see the installation instructions for more information.

Loading Exercises into Delphi

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.

Alternatively you may opt to start Delphi and load your project via. the File drop down menu.

When Questions Come Up

We monitor the Pascal-Delphi support room on gitter.im to help you with any questions that might arise.

Submitting Exercises

Note that, when trying to submit an exercise, make sure the exercise file you're submitting is in the exercism/delphi/<exerciseName> directory.

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.

Source

Introductory challenge to reverse an input string https://medium.freecodecamp.org/how-to-reverse-a-string-in-javascript-in-3-different-ways-75e4763c68cb

Submitting Incomplete Solutions

It's possible to submit an incomplete solution so you may request help from a mentor.

uReverseStringTests.pas

unit uReverseStringTests;

interface
uses
  DUnitX.TestFramework;

const
   CanonicalVersion = '1.2.0';

type

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

    [Test]
    [Ignore]
    procedure a_word;

    [Test]
    [Ignore]
    procedure a_capitalized_word;

    [Test]
    [Ignore]
    procedure a_sentence_with_punctuation;

    [Test]
    [Ignore]
    procedure a_palindrome;

    [Test]
    [Ignore]
    procedure an_even_sized_word;
  end;

implementation
uses uReverseString;


{ ReverseStringTest }

procedure ReverseStringTest.an_empty_string;
begin
  Assert.AreEqual('', reverse(''));
end;

procedure ReverseStringTest.an_even_sized_word;
begin
  Assert.AreEqual('reward',reverse('drawer'));
end;

procedure ReverseStringTest.a_capitalized_word;
begin
  Assert.AreEqual('nemaR',reverse('Ramen'));
end;

procedure ReverseStringTest.a_palindrome;
begin
  Assert.AreEqual('racecar',reverse('racecar'));
end;

procedure ReverseStringTest.a_sentence_with_punctuation;
begin
  Assert.AreEqual('!yrgnuh m''I', reverse('I''m hungry!'));
end;

procedure ReverseStringTest.a_word;
begin
  Assert.AreEqual('tobor', reverse('robot'));
end;

initialization
  TDUnitX.RegisterTestFixture(ReverseStringTest);
end.
unit uReverseString;

interface

function reverse(AValue: String): String;

implementation

function reverse(AValue: String): String;
var
  I: Integer;
begin
  for I := High(AValue) downto 1 do
    Result := Result + AValue[i];
end;

end.

Community comments

Find this solution interesting? Ask the author a question to learn more.

What can you learn from this solution?

A huge amount can be learned from reading other people’s code. This is why we wanted to give exercism users the option of making their solutions public.

Here are some questions to help you reflect on this solution and learn the most from it.

  • What compromises have been made?
  • Are there new concepts here that you could read more about to improve your understanding?