Skip to content

Commit fd6c736

Browse files
committed
Added powershell test and clockhands from Toal's Notes
1 parent 2617fb4 commit fd6c736

File tree

3 files changed

+83
-0
lines changed

3 files changed

+83
-0
lines changed

c/clockhands.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include <stdio.h>
2+
int main()
3+
{
4+
for (int i = 0; i < 11; i++)
5+
{
6+
int t = (43200 * i + 21600) / 11;
7+
int h = t / 3600, m = t / 60 % 60, s = t % 60;
8+
printf("%02d:%02d:%02d\n", (h ? h : 12), m, s);
9+
}
10+
return 0;
11+
}

c/clockhands_time.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include <time.h>
2+
#include <stdio.h>
3+
#include <stdlib.h>
4+
int main()
5+
{
6+
for (int i = 0; i < 11; i++)
7+
{
8+
char s[9];
9+
time_t t = (time_t)((43200 * i + 21600) / 11);
10+
strftime(s, 9, "%I:%M:%S", gmtime(&t));
11+
printf("%s\n", s);
12+
}
13+
return 0;
14+
}

c/test.ps1

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
$run = "$PSScriptRoot\a.exe"
12+
13+
$Error.clear()
14+
# gcc -std=c2x "$PSScriptRoot\anagrams.c" && . $run rats |
15+
# Compare-Object (Get-Content "$PSScriptRoot\..\test\rats_heap_expected") |
16+
# Assert-MatchTests &&
17+
gcc -std=c2x "$PSScriptRoot\array_in_struct.c" && . $run &&
18+
gcc -std=c2x "$PSScriptRoot\assignment.c" && . $run &&
19+
gcc -std=c2x "$PSScriptRoot\cheating_with_pointers.c" && . $run &&
20+
gcc -std=c2x "$PSScriptRoot\clockhands_time.c" && . $run |
21+
Compare-Object (Get-Content "$PSScriptRoot\..\test\clockhands_expected") |
22+
Assert-MatchTests &&
23+
gcc -std=c2x "$PSScriptRoot\clockhands.c" && . $run |
24+
Compare-Object (Get-Content "$PSScriptRoot\..\test\clockhands_expected") |
25+
Assert-MatchTests &&
26+
gcc -std=c2x "$PSScriptRoot\const.c" && . $run &&
27+
gcc -std=c2x "$PSScriptRoot\directives.c" && . $run &&
28+
gcc -std=c2x -c "$PSScriptRoot\hashmap.c" &&
29+
gcc -std=c2x "$PSScriptRoot\indexing.c" && . $run &&
30+
gcc -std=c2x "$PSScriptRoot\memory.c" && . $run &&
31+
gcc -std=c2x "$PSScriptRoot\permutations.c" && . $run I like carrots |
32+
Compare-Object (Get-Content "$PSScriptRoot\..\test\carrots_expected") |
33+
Assert-MatchTests &&
34+
gcc -std=c2x "$PSScriptRoot\reinterpret_cast.c" && . $run &&
35+
gcc -std=c2x "$PSScriptRoot\simple_macro.c" && . $run &&
36+
gcc -std=c2x "$PSScriptRoot\sizeof.c" && . $run &&
37+
gcc -std=c2x "$PSScriptRoot\sum_of_even_squares.c" && . $run &&
38+
gcc -std=c2x "$PSScriptRoot\sum.c" && . $run &&
39+
# gcc -std=c2x "$PSScriptRoot\top_ten_scorers.c" && Get-Content "$PSScriptRoot\..\test\wnba_input" | . $run |
40+
# Compare-Object (Get-Content "$PSScriptRoot\..\test\wnba_expected") |
41+
# Assert-MatchTests &&
42+
gcc -std=c2x "$PSScriptRoot\triple.c" && . $run |
43+
Compare-Object (Get-Content "$PSScriptRoot\..\test\triple_expected") |
44+
Assert-MatchTests &&
45+
gcc -std=c2x "$PSScriptRoot\ugly_pointer_arithmetic.c" && . $run &&
46+
gcc -std=c2x "$PSScriptRoot\union.c" && . $run &&
47+
# gcc -std=c2x "$PSScriptRoot\wordcount.c" && Get-Content "$PSScriptRoot\..\test\wordcount_ascii_input" | . $run |
48+
# Compare-Object (Get-Content "$PSScriptRoot\..\test\wordcount_ascii_expected") |
49+
# Assert-MatchTests &&
50+
gcc -std=c2x "$PSScriptRoot\x_is_x.c" && . $run &&
51+
ForEach-Object 'foo'
52+
53+
if ($Error -or !$?) {
54+
"*** C TESTS FAILED ***"
55+
}
56+
else {
57+
"C TESTS PASSED"
58+
}

0 commit comments

Comments
 (0)