Skip to content

Commit 99693bb

Browse files
committed
Feature: Add fixtures for STDOUT testing
1 parent f41be4b commit 99693bb

4 files changed

Lines changed: 26 additions & 1 deletion

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
{
3+
// Use the Gregory-Leibniz series.
4+
function calculatePI(cycles: number): number {
5+
let pi = 0;
6+
let i = 1;
7+
8+
while (i < cycles) {
9+
pi = pi + (4 / i);
10+
pi = pi - (4 / (i + 2));
11+
12+
i = i + 4;
13+
}
14+
15+
return pi;
16+
}
17+
18+
console_log("Gregory-Leibniz series");
19+
console_log(calculatePI(500000));
20+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Gregory-Leibniz series
2+
3.141589

tests/snapshots/examples/calculate-pi.ts renamed to tests/snapshots/examples/calculate-pi-monte.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
{
3+
// Monte Carlo simulation
34
function calculatePI(cycles: number): number {
45
let inside = 0;
56

@@ -15,5 +16,6 @@
1516
return 4.0 * inside / cycles;
1617
}
1718

18-
console_log(calculatePI(1000000000));
19+
console_log("Monte Carlo simulation");
20+
console_log(calculatePI(10000000));
1921
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3628800.000000

0 commit comments

Comments
 (0)