Skip to content

Commit 00a8895

Browse files
committed
Added more AWK files + test
1 parent 1c053b8 commit 00a8895

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

awk/clockhands.awk

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

awk/clockhands_time.awk

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
BEGIN {
2+
for (i = 0; i < 11; i++) {
3+
print strftime("%I:%M:%S", (43200 * i + 21600) / 11, 1)
4+
}
5+
}

awk/test.ps1

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
function Assert-MatchTests {
2+
param (
3+
[Parameter(Mandatory = $true, ValueFromPipeline)] $TestResult
4+
)
5+
6+
if ($null -ne $TestResult) {
7+
Write-Error "Output does not match expected results."
8+
}
9+
}
10+
11+
$Error.clear()
12+
awk -E "$PSScriptRoot\clockhands_time.awk" |
13+
Compare-Object (Get-Content "$PSScriptRoot\..\test\clockhands_expected") |
14+
Assert-MatchTests &&
15+
awk -E "$PSScriptRoot\clockhands.awk" |
16+
Compare-Object (Get-Content "$PSScriptRoot\..\test\clockhands_expected") |
17+
Assert-MatchTests &&
18+
Get-Content "$PSScriptRoot\..\test\wordcount_ascii_input" |
19+
awk -E "$PSScriptRoot\wordcount.awk" |
20+
Compare-Object (Get-Content "$PSScriptRoot\..\test\wordcount_ascii_expected") |
21+
Assert-MatchTests &&
22+
ForEach-Object 'foo';
23+
24+
if ($Error -or !$?) {
25+
"*** AWK TESTS FAILED ***"
26+
}
27+
else {
28+
"AWK TESTS PASSED"
29+
}

0 commit comments

Comments
 (0)