2017-08-15
This commit is contained in:
parent
63b955575a
commit
88b47de8c8
52
d/hello-world/README.md
Normal file
52
d/hello-world/README.md
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
# Hello World
|
||||||
|
|
||||||
|
The classical introductory exercise. Just say "Hello, World!".
|
||||||
|
|
||||||
|
["Hello, World!"](http://en.wikipedia.org/wiki/%22Hello,_world!%22_program) is
|
||||||
|
the traditional first program for beginning programming in a new language
|
||||||
|
or environment.
|
||||||
|
|
||||||
|
The objectives are simple:
|
||||||
|
|
||||||
|
- Write a function that returns the string "Hello, World!".
|
||||||
|
- Run the test suite and make sure that it succeeds.
|
||||||
|
- Submit your solution and check it at the website.
|
||||||
|
|
||||||
|
If everything goes well, you will be ready to fetch your first real exercise.
|
||||||
|
|
||||||
|
## Getting Started
|
||||||
|
|
||||||
|
Make sure you have read [D page](http://exercism.io/languages/dlang) on
|
||||||
|
exercism.io. This covers the basic information on setting up the development
|
||||||
|
environment expected by the exercises.
|
||||||
|
|
||||||
|
## Passing the Tests
|
||||||
|
|
||||||
|
Get the first test compiling, linking and passing by following the [three
|
||||||
|
rules of test-driven development](http://butunclebob.com/ArticleS.UncleBob.TheThreeRulesOfTdd).
|
||||||
|
Create just enough structure by declaring namespaces, functions, classes,
|
||||||
|
etc., to satisfy any compiler errors and get the test to fail. Then write
|
||||||
|
just enough code to get the test to pass. Once you've done that,
|
||||||
|
uncomment the next test by moving the following line past the next test.
|
||||||
|
|
||||||
|
```D
|
||||||
|
static if (all_tests_enabled)
|
||||||
|
```
|
||||||
|
|
||||||
|
This may result in compile errors as new constructs may be invoked that
|
||||||
|
you haven't yet declared or defined. Again, fix the compile errors minimally
|
||||||
|
to get a failing test, then change the code minimally to pass the test,
|
||||||
|
refactor your implementation for readability and expressiveness and then
|
||||||
|
go on to the next test.
|
||||||
|
|
||||||
|
Try to use standard D facilities in preference to writing your own
|
||||||
|
low-level algorithms or facilities by hand. [DRefLanguage](https://dlang.org/spec/spec.html)
|
||||||
|
and [DReference](https://dlang.org/phobos/index.html) are references to the D language and D standard library.
|
||||||
|
|
||||||
|
|
||||||
|
## Source
|
||||||
|
|
||||||
|
This is an exercise to introduce users to using Exercism [http://en.wikipedia.org/wiki/%22Hello,_world!%22_program](http://en.wikipedia.org/wiki/%22Hello,_world!%22_program)
|
||||||
|
|
||||||
|
## Submitting Incomplete Solutions
|
||||||
|
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
|
2
d/hello-world/dub.sdl
Normal file
2
d/hello-world/dub.sdl
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
name "hello-world"
|
||||||
|
buildRequirements "disallowDeprecations"
|
13
d/hello-world/source/hello_world.d
Normal file
13
d/hello-world/source/hello_world.d
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
module helloworld_test;
|
||||||
|
|
||||||
|
unittest {
|
||||||
|
const int allTestsEnabled = 0;
|
||||||
|
|
||||||
|
assert(hello() == "Hello, World!");
|
||||||
|
static if (allTestsEnabled) {
|
||||||
|
assert(hello("Alice") == "Hello, Alice!");
|
||||||
|
assert(hello("Bob") == "Hello, Bob!");
|
||||||
|
assert(hello("") == "Hello, !");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
60
delphi/hello-world/HelloWorld.dpr
Normal file
60
delphi/hello-world/HelloWorld.dpr
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
program HelloWorld;
|
||||||
|
|
||||||
|
{$IFNDEF TESTINSIGHT}
|
||||||
|
{$APPTYPE CONSOLE}
|
||||||
|
{$ENDIF}{$STRONGLINKTYPES ON}
|
||||||
|
uses
|
||||||
|
System.SysUtils,
|
||||||
|
{$IFDEF TESTINSIGHT}
|
||||||
|
TestInsight.DUnitX,
|
||||||
|
{$ENDIF }
|
||||||
|
DUnitX.Loggers.Console,
|
||||||
|
DUnitX.Loggers.Xml.NUnit,
|
||||||
|
DUnitX.TestFramework,
|
||||||
|
uTestHelloWorld in 'uTestHelloWorld.pas',
|
||||||
|
uHelloWorld in 'uHelloWorld.pas';
|
||||||
|
|
||||||
|
var
|
||||||
|
runner : ITestRunner;
|
||||||
|
results : IRunResults;
|
||||||
|
logger : ITestLogger;
|
||||||
|
nunitLogger : ITestLogger;
|
||||||
|
begin
|
||||||
|
{$IFDEF TESTINSIGHT}
|
||||||
|
TestInsight.DUnitX.RunRegisteredTests;
|
||||||
|
exit;
|
||||||
|
{$ENDIF}
|
||||||
|
try
|
||||||
|
//Check command line options, will exit if invalid
|
||||||
|
TDUnitX.CheckCommandLine;
|
||||||
|
//Create the test runner
|
||||||
|
runner := TDUnitX.CreateRunner;
|
||||||
|
//Tell the runner to use RTTI to find Fixtures
|
||||||
|
runner.UseRTTI := True;
|
||||||
|
//tell the runner how we will log things
|
||||||
|
//Log to the console window
|
||||||
|
logger := TDUnitXConsoleLogger.Create(true);
|
||||||
|
runner.AddLogger(logger);
|
||||||
|
//Generate an NUnit compatible XML File
|
||||||
|
nunitLogger := TDUnitXXMLNUnitFileLogger.Create(TDUnitX.Options.XMLOutputFile);
|
||||||
|
runner.AddLogger(nunitLogger);
|
||||||
|
runner.FailsOnNoAsserts := False; //When true, Assertions must be made during tests;
|
||||||
|
|
||||||
|
//Run tests
|
||||||
|
results := runner.Execute;
|
||||||
|
if not results.AllPassed then
|
||||||
|
System.ExitCode := EXIT_ERRORS;
|
||||||
|
|
||||||
|
{$IFNDEF CI}
|
||||||
|
//We don't want this happening when running under CI.
|
||||||
|
if TDUnitX.Options.ExitBehavior = TDUnitXExitBehavior.Pause then
|
||||||
|
begin
|
||||||
|
System.Write('Done.. press <Enter> key to quit.');
|
||||||
|
System.Readln;
|
||||||
|
end;
|
||||||
|
{$ENDIF}
|
||||||
|
except
|
||||||
|
on E: Exception do
|
||||||
|
System.Writeln(E.ClassName, ': ', E.Message);
|
||||||
|
end;
|
||||||
|
end.
|
42
delphi/hello-world/README.md
Normal file
42
delphi/hello-world/README.md
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
# Hello World
|
||||||
|
|
||||||
|
The classical introductory exercise. Just say "Hello, World!".
|
||||||
|
|
||||||
|
["Hello, World!"](http://en.wikipedia.org/wiki/%22Hello,_world!%22_program) is
|
||||||
|
the traditional first program for beginning programming in a new language
|
||||||
|
or environment.
|
||||||
|
|
||||||
|
The objectives are simple:
|
||||||
|
|
||||||
|
- Write a function that returns the string "Hello, World!".
|
||||||
|
- Run the test suite and make sure that it succeeds.
|
||||||
|
- Submit your solution and check it at the website.
|
||||||
|
|
||||||
|
If everything goes well, you will be ready to fetch your first real exercise.
|
||||||
|
|
||||||
|
## Testing
|
||||||
|
|
||||||
|
In order to run the tests for this track, you will need to install
|
||||||
|
DUnitX. Please see the [installation](http://www.exercism.io/languages/delphi/installing) 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](https://gitter.im/exercism/Pascal-Delphi) support room on [gitter.im](https://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
|
||||||
|
|
||||||
|
This is an exercise to introduce users to using Exercism [http://en.wikipedia.org/wiki/%22Hello,_world!%22_program](http://en.wikipedia.org/wiki/%22Hello,_world!%22_program)
|
||||||
|
|
||||||
|
## Submitting Incomplete Solutions
|
||||||
|
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
|
85
delphi/hello-world/uTestHelloWorld.pas
Normal file
85
delphi/hello-world/uTestHelloWorld.pas
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
(******************************************************************************
|
||||||
|
You got an error, which is exactly as it should be.
|
||||||
|
This is the first step in the Test-Driven Development
|
||||||
|
(TDD) process.
|
||||||
|
|
||||||
|
The most important part of the error is
|
||||||
|
|
||||||
|
"cannot compile"
|
||||||
|
|
||||||
|
It's looking for a file named uHelloWorld.pas that doesn't exist.
|
||||||
|
|
||||||
|
To fix the error, create a unit file named uHelloWorld.pas
|
||||||
|
in the same directory as the file uTestHelloWorld.pas.
|
||||||
|
|
||||||
|
The beginning of the new unit file should contain a unit statement:
|
||||||
|
|
||||||
|
unit uHelloWorld;
|
||||||
|
|
||||||
|
The new unit should contain Interface, Implementation, and End. statements.
|
||||||
|
|
||||||
|
The primary focus of this exercise is to provide you with a very simple
|
||||||
|
exercise that you can use to test the tools necessary for this language track,
|
||||||
|
are working correctly. To that end we are providing you with code that you may
|
||||||
|
use as the solution to this exercise:
|
||||||
|
|
||||||
|
{------------------< start solution >------------------}
|
||||||
|
unit uHelloWorld;
|
||||||
|
|
||||||
|
interface
|
||||||
|
|
||||||
|
function Hello: string;
|
||||||
|
|
||||||
|
implementation
|
||||||
|
|
||||||
|
function Hello: string;
|
||||||
|
begin
|
||||||
|
result := 'Hello, World!';
|
||||||
|
end;
|
||||||
|
|
||||||
|
end.
|
||||||
|
{------------------< end solution >------------------}
|
||||||
|
|
||||||
|
Hint: Delphi will take care of all this if you instruct it to add a new unit
|
||||||
|
to your project. Be sure to save the new unit as uHelloWorld.pas before
|
||||||
|
trying to compile again.
|
||||||
|
|
||||||
|
For more guidance as you work on this exercise, see
|
||||||
|
GETTING_STARTED.md.
|
||||||
|
******************************************************************************)
|
||||||
|
unit uTestHelloWorld;
|
||||||
|
|
||||||
|
interface
|
||||||
|
uses
|
||||||
|
DUnitX.TestFramework;
|
||||||
|
|
||||||
|
type
|
||||||
|
[TestFixture]
|
||||||
|
HelloWorldTest = class(TObject)
|
||||||
|
public
|
||||||
|
[Test]
|
||||||
|
procedure Say_hi;
|
||||||
|
end;
|
||||||
|
|
||||||
|
implementation
|
||||||
|
uses uHelloWorld;
|
||||||
|
|
||||||
|
procedure HelloWorldTest.Say_hi;
|
||||||
|
var
|
||||||
|
Expected: string;
|
||||||
|
Actual: string;
|
||||||
|
begin
|
||||||
|
Expected := 'Hello, World!'; //Expected: This is what is expected to be returned by the function/method (Hello)
|
||||||
|
Actual := Hello; //Actual: This is what is actually returned by the function/method (Hello)
|
||||||
|
Assert.AreEqual(Expected, Actual);
|
||||||
|
|
||||||
|
//As you progress in this track you will find that not every exercise has Expected and
|
||||||
|
//Actual defined as explicitly as they have been above. Often times you may find
|
||||||
|
//that the Expected outcome is inserted as an inline statement and the the call
|
||||||
|
//to the method being tested will be inserted in the Actual position of AreEqual like so:
|
||||||
|
//Assert.AreEqual('Hello, World!', Hello);
|
||||||
|
end;
|
||||||
|
|
||||||
|
initialization
|
||||||
|
TDUnitX.RegisterTestFixture(HelloWorldTest);
|
||||||
|
end.
|
15
perl6/hello-world/HelloWorld.pm6
Normal file
15
perl6/hello-world/HelloWorld.pm6
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#`( |