Skip to content

Commit dfe1cfc

Browse files
committed
Added Pascal Scripts
1 parent 3a399c6 commit dfe1cfc

File tree

5 files changed

+84
-0
lines changed

5 files changed

+84
-0
lines changed

pascal/clockhands.pas

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
uses sysutils;
2+
3+
var
4+
i, t, h, m, s : longint;
5+
begin
6+
for i := 0 to 10 do
7+
begin
8+
t := trunc ((i + 0.5) * 43200 / 11);
9+
h := trunc (t / 3600);
10+
m := (trunc (t / 60)) mod 60;
11+
s := t mod 60;
12+
if h = 0 then h := 12;
13+
WriteLn(Format('%0.02d:%0.02d:%0.02d', [h, m, s]));
14+
end;
15+
end.

pascal/hello.pas

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
begin
2+
write('Hello, World!');
3+
end.

pascal/reserved_word_identifiers.pas

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
var
2+
&var : integer;
3+
4+
begin
5+
&var:=1;
6+
Writeln(&var);
7+
end.

pascal/test.ps1

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
function Assert-MatchTests {
2+
param (
3+
[Parameter(Mandatory = $true, ValueFromPipeline)] $TestResult
4+
)
5+
6+
if ($TestResult) {
7+
Write-Error "Output does not match expected results."
8+
}
9+
}
10+
11+
$bin = "$PSScriptRoot\bin"
12+
13+
# First check if folder bin exists. If not, make a new bin folder.
14+
if (!(Test-Path -Path $bin)) {
15+
New-Item -Path $bin -Type Directory
16+
}
17+
18+
$Error.clear()
19+
fpc "$PSScriptRoot\clockhands.pas" && . "$PSScriptRoot\clockhands.exe" |
20+
Compare-Object (Get-Content "$PSScriptRoot\..\test\clockhands_expected") |
21+
Assert-MatchTests &&
22+
fpc "$PSScriptRoot\hello.pas" && . "$PSScriptRoot\hello.exe" &&
23+
fpc "$PSScriptRoot\reserved_word_identifiers.pas" && . "$PSScriptRoot\reserved_word_identifiers.exe" &&
24+
fpc "$PSScriptRoot\triple.pas" && . "$PSScriptRoot\triple.exe" |
25+
Compare-Object (Get-Content "$PSScriptRoot\..\test\triple_expected") |
26+
Assert-MatchTests &&
27+
ForEach-Object 'foo';
28+
29+
if ($Error -or !$?) {
30+
"*** PASCAL TESTS FAILED ***"
31+
}
32+
else {
33+
"PASCAL TESTS PASSED"
34+
}

pascal/triple.pas

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
uses sysutils;
2+
3+
var
4+
n, a, b, c : integer;
5+
6+
Operator ** (num1 : smallint; num2 : shortint) exp : smallint;
7+
begin
8+
exp := 1;
9+
for n := 1 to num2 do
10+
exp := exp * num1;
11+
end;
12+
13+
begin
14+
for c := 1 to 40 do
15+
begin
16+
for b := 1 to c do
17+
begin
18+
for a := 1 to b do
19+
begin
20+
if a ** 2 + b ** 2 = c ** 2 then
21+
WriteLn(Format('%d, %d, %d', [a, b, c]));
22+
end;
23+
end;
24+
end;
25+
end.

0 commit comments

Comments
 (0)