Skip to content

Commit f882759

Browse files
committed
Run Fantomas against validation examples
1 parent 5358566 commit f882759

29 files changed

+255
-199
lines changed

src/Fantomas.Cmd/Fantomas.Cmd.fsproj

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
<PlatformTarget>AnyCPU</PlatformTarget>
3636
<DocumentationFile>bin\Release\Fantomas.XML</DocumentationFile>
3737
<Prefer32Bit>true</Prefer32Bit>
38+
<StartArguments>../../../../tests/stackexchange --out ../../../../tests/stackexchange_output --indent 2</StartArguments>
3839
</PropertyGroup>
3940
<ItemGroup>
4041
<Reference Include="mscorlib" />
@@ -73,4 +74,4 @@
7374
<Target Name="AfterBuild">
7475
</Target>
7576
-->
76-
</Project>
77+
</Project>

src/Fantomas.Tests/FunctionDefinitionTests.fs

+12
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,16 @@ let ``should add spaces between multiline nested let bindings``() =
142142
y + 1
143143
144144
x + y
145+
"""
146+
147+
[<Test>]
148+
let ``should indent fun blocks``() =
149+
formatSourceString false """let f =
150+
fun x ->
151+
let y = 1
152+
x""" config
153+
|> should equal """let f =
154+
fun x ->
155+
let y = 1
156+
x
145157
"""

tests/languageshootout_output/binarytrees.fs

+3-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ and [<Struct>] Tree(next : Next, item : int) =
2222

2323
let rec make item depth =
2424
if depth > 0 then
25-
Tree(
26-
{ Left = make (2 * item - 1) (depth - 1)
25+
Tree({ Left = make (2 * item - 1) (depth - 1)
2726
Right = make (2 * item) (depth - 1) }, item)
2827
else Tree(defaultof<_>, item)
2928

@@ -41,11 +40,13 @@ let rec loopDepths maxDepth minDepth d =
4140
[<EntryPoint>]
4241
let main args =
4342
let minDepth = 4
43+
4444
let maxDepth =
4545
let n =
4646
if args.Length > 0 then int args.[0]
4747
else 10
4848
max (minDepth + 2) n
49+
4950
let stretchDepth = maxDepth + 1
5051
let c = check (make 0 stretchDepth)
5152
Console.WriteLine("stretch tree of depth {0}\t check: {1}", stretchDepth, c)

tests/languageshootout_output/binarytrees2.fs

+2
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,13 @@ let rec loopDepths maxDepth minDepth d =
3636
[<EntryPoint>]
3737
let main args =
3838
let minDepth = 4
39+
3940
let maxDepth =
4041
let n =
4142
if args.Length > 0 then int args.[0]
4243
else 10
4344
max (minDepth + 2) n
45+
4446
let stretchDepth = maxDepth + 1
4547
let c = check (make 0 stretchDepth)
4648
printf "stretch tree of depth %i\t check: %i\n" stretchDepth c

tests/languageshootout_output/fannkuch5.fs

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ let main (args) =
99
let n =
1010
if args.Length > 0 then int args.[0]
1111
else 7
12+
1213
//printfn "Pfannkuchen(%d) = %d" x (fannkuch x)
1314
let mutable maxFlips = 0
1415
let mutable permN = 0

tests/languageshootout_output/fannkuchredux2.fs

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ let _ =
5656
let n =
5757
try
5858
int ((System.Environment.GetCommandLineArgs()).[1])
59-
with
60-
| _ -> 7
59+
with _ -> 7
60+
6161
let (maxflips, checksum) = fannkuch n
6262
Printf.printf "%d\nPfannkuchen(%d) = %d\n" checksum n maxflips

tests/languageshootout_output/fannkuchredux3.fs

+8-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ let rec fac x =
1414
else (int64 x) * fac (x - 1)
1515

1616
let F =
17-
[0..20]
17+
[ 0..20 ]
1818
|> Seq.map fac
1919
|> Seq.toArray
2020

@@ -93,20 +93,23 @@ type fannkuch(n) =
9393

9494
let _ =
9595
let nthreads = System.Environment.ProcessorCount
96+
9697
let n =
9798
try
9899
int ((System.Environment.GetCommandLineArgs()).[1])
99-
with
100-
| _ -> 7
100+
with _ -> 7
101+
101102
let split (i : int64) = (F.[n] + i - 1L) / i
102103
let chunk = split (int64 (nthreads * 4))
103104
let ntasks = int (split chunk)
105+
104106
let (c, fl) =
105-
[0..ntasks]
107+
[ 0..ntasks ]
106108
|> Seq.map (fun i ->
107109
async {
108110
let thread = fannkuch (n)
109-
return thread.runTask (i, chunk) })
111+
return thread.runTask (i, chunk)
112+
})
110113
|> Async.Parallel
111114
|> Async.RunSynchronously
112115
|> Array.fold

tests/languageshootout_output/fasta.fs

+21-21
Original file line numberDiff line numberDiff line change
@@ -27,30 +27,31 @@ let makeCumulative =
2727
>> List.toArray
2828

2929
let homoSapiens =
30-
makeCumulative ['a'B, 0.3029549426680
31-
'c'B, 0.1979883004921
32-
'g'B, 0.1975473066391
33-
't'B, 0.3015094502008]
30+
makeCumulative [ 'a'B, 0.3029549426680
31+
'c'B, 0.1979883004921
32+
'g'B, 0.1975473066391
33+
't'B, 0.3015094502008 ]
3434

3535
let iub =
36-
makeCumulative ['a'B, 0.27
37-
'c'B, 0.12
38-
'g'B, 0.12
39-
't'B, 0.27
40-
'B'B, 0.02
41-
'D'B, 0.02
42-
'H'B, 0.02
43-
'K'B, 0.02
44-
'M'B, 0.02
45-
'N'B, 0.02
46-
'R'B, 0.02
47-
'S'B, 0.02
48-
'V'B, 0.02
49-
'W'B, 0.02
50-
'Y'B, 0.02]
36+
makeCumulative [ 'a'B, 0.27
37+
'c'B, 0.12
38+
'g'B, 0.12
39+
't'B, 0.27
40+
'B'B, 0.02
41+
'D'B, 0.02
42+
'H'B, 0.02
43+
'K'B, 0.02
44+
'M'B, 0.02
45+
'N'B, 0.02
46+
'R'B, 0.02
47+
'S'B, 0.02
48+
'V'B, 0.02
49+
'W'B, 0.02
50+
'Y'B, 0.02 ]
5151

5252
let inline selectRandom (f : _ []) =
5353
let r = random 1.0
54+
5455
let rec find =
5556
function
5657
| 0 -> fst f.[0]
@@ -91,8 +92,7 @@ let main args =
9192
let n =
9293
try
9394
int args.[0]
94-
with
95-
| _ -> 1000
95+
with _ -> 1000
9696
repeatFasta ">ONE Homo sapiens alu\n"B alu (2 * n)
9797
randomFasta ">TWO IUB ambiguity codes\n"B iub (3 * n)
9898
randomFasta ">THREE Homo sapiens frequency\n"B homoSapiens (5 * n)

tests/languageshootout_output/fastaredux2.fs

+11-8
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,20 @@ let alu = "GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGG\
1717
GCTACTCGGGAGGCTGAGGCAGGAGAATCGCTTGAACCCGGG\
1818
AGGCGGAGGTTGCAGTGAGCCGAGATCGCGCCACTGCACTCC\
1919
AGCCTGGGCGACAGAGCGAGACTCCGTCTCAAAAA"B
20-
let iubvalues = [0.27; 0.12; 0.12; 0.27] @ List.replicate 12 0.02
20+
let iubvalues = [ 0.27; 0.12; 0.12; 0.27 ] @ List.replicate 12 0.02
2121
let iub = Seq.zip "acgtBDHKMNRSVWY"B iubvalues
2222

2323
let homosapien =
24-
['a'B, 0.3029549426680
25-
'c'B, 0.1979883004921
26-
'g'B, 0.1975473066391
27-
't'B, 0.3015094502008]
24+
[ 'a'B, 0.3029549426680
25+
'c'B, 0.1979883004921
26+
'g'B, 0.1975473066391
27+
't'B, 0.3015094502008 ]
2828

2929
let os = new BufferedStream(Console.OpenStandardOutput(), 1 <<< 16)
3030

3131
let repeatFasta alu n =
3232
let r = Array.length alu
33-
let s = Array.concat [alu; alu]
33+
let s = Array.concat [ alu; alu ]
3434
for j in 0..cols..n - cols do
3535
os.Write(s, j % r, cols)
3636
os.WriteByte('\n'B)
@@ -45,6 +45,7 @@ let randomFasta src n =
4545
src
4646
|> Seq.scan f (0uy, 0.0, 0)
4747
|> Seq.toArray
48+
4849
/// lookup table optimization
4950
let lut =
5051
let arr = Array.zeroCreate LUTLEN
@@ -56,6 +57,7 @@ let randomFasta src n =
5657
j <- j + 1
5758
if j <> v then arr.[j - 1] <- 0uy, i
5859
arr
60+
5961
let lookup x =
6062
match lut.[x * (LUTLEN - 1) / IM] with
6163
| 0uy, p ->
@@ -64,8 +66,10 @@ let randomFasta src n =
6466
if float (x) / float (IM) < b then a
6567
else i
6668
| c, p -> c
69+
6770
/// write output one line at a time
6871
let buf = Array.zeroCreate (cols + 1)
72+
6973
for x in n..(-cols)..1 do
7074
let e =
7175
if x < cols then x
@@ -82,8 +86,7 @@ let main args =
8286
let n =
8387
try
8488
int args.[0]
85-
with
86-
| _ -> 2500000
89+
with _ -> 2500000
8790
printfn ">ONE Homo sapiens alu"
8891
repeatFasta alu (2 * n)
8992
printfn ">TWO IUB ambiguity codes"

tests/languageshootout_output/knucleotide.fs

+20-18
Original file line numberDiff line numberDiff line change
@@ -22,38 +22,40 @@ let maketable (dna : string) (length : int) =
2222

2323
/// frequency for all substrings of a given length
2424
let frequencies (dna : string) (length : int) =
25-
[let d = maketable dna length
26-
let total =
27-
d.Values
28-
|> Seq.map (!)
29-
|> Seq.sum
30-
yield! [for pair in d ->
31-
pair.Key.ToUpper(),
32-
(float (pair.Value.Value) * 100.0 / float (total))]
33-
|> List.sortBy (snd >> (~-))
34-
|> List.map (fun (s, c) -> sprintf "%s %.3f" s c)
35-
yield ""]
25+
[ let d = maketable dna length
26+
27+
let total =
28+
d.Values
29+
|> Seq.map (!)
30+
|> Seq.sum
31+
yield! [ for pair in d ->
32+
pair.Key.ToUpper(),
33+
(float (pair.Value.Value) * 100.0 / float (total)) ]
34+
|> List.sortBy (snd >> (~-))
35+
|> List.map (fun (s, c) -> sprintf "%s %.3f" s c)
36+
yield "" ]
3637

3738
// frequency of occurrence for a particular substring
3839
let countSubstring dna (substring : string) =
39-
[let d = maketable dna (substring.Length)
40-
yield (sprintf "%d\t%s" (if d.ContainsKey(substring) then !d.[substring]
41-
else 0) (substring.ToUpper()))]
40+
[ let d = maketable dna (substring.Length)
41+
yield (sprintf "%d\t%s" (if d.ContainsKey(substring) then !d.[substring]
42+
else 0) (substring.ToUpper())) ]
4243

4344
let input = Console.In
4445

4546
let dna =
4647
seq {
4748
while true do
48-
yield input.ReadLine() }
49+
yield input.ReadLine()
50+
}
4951
|> Seq.takeWhile (fun x -> x <> null)
5052
|> Seq.skipWhile (fun x -> not (x.StartsWith(">THREE")))
5153
|> Seq.skip 1
5254
|> String.concat ""
5355

54-
[for len in [1; 2] -> async { return frequencies dna len }]
55-
@ [for str in ["ggt"; "ggta"; "ggtatt"; "ggtattttaatt"; "ggtattttaatttatagt"] ->
56-
async { return countSubstring dna str }]
56+
[ for len in [ 1; 2 ] -> async { return frequencies dna len } ]
57+
@ [ for str in [ "ggt"; "ggta"; "ggtatt"; "ggtattttaatt"; "ggtattttaatttatagt" ] ->
58+
async { return countSubstring dna str } ]
5759
|> List.rev
5860
|> Async.Parallel
5961
|> Async.RunSynchronously

tests/languageshootout_output/nbody.fs

+4-3
Original file line numberDiff line numberDiff line change
@@ -96,18 +96,20 @@ let advance a t =
9696
let rec energy i e a =
9797
if i < Array.length a then
9898
let b1 = a.[i]
99+
99100
let rec energy' a j e =
100101
if j < Array.length a then
101102
let b2 = a.[j]
102103
let dx, dy, dz = b1.X - b2.X, b1.Y - b2.Y, b1.Z - b2.Z
103104
let dist = sqrt (dx * dx + dy * dy + dz * dz)
104105
energy' a (j + 1) (e - b1.Mass * b2.Mass / dist)
105106
else e
107+
106108
let sq = b1.VX * b1.VX + b1.VY * b1.VY + b1.VZ * b1.VZ
107109
energy (i + 1) (energy' a (i + 1) (e + 0.5 * b1.Mass * sq)) a
108110
else e
109111

110-
let planets = [|sun; jupiter; saturn; uranus; neptune|]
112+
let planets = [| sun; jupiter; saturn; uranus; neptune |]
111113

112114
offsetMomentum planets
113115

@@ -118,8 +120,7 @@ let main args =
118120
let n =
119121
try
120122
int args.[0]
121-
with
122-
| _ -> 20000000
123+
with _ -> 20000000
123124
print planets
124125
for i in 1..n do
125126
advance planets 0.01

tests/languageshootout_output/pidigits.fs

+6-4
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@ let prod (u, v, w, x) n =
2424

2525
let digits =
2626
let z = ref id
27+
2728
let lfts =
2829
let n = ref 0I
2930
fun () ->
30-
n := !n + 1I
31-
!n, 4I * !n + 2I, 2I * !n + 1I
31+
n := !n + 1I
32+
!n, 4I * !n + 2I, 2I * !n + 1I
33+
3234
let rec digits() =
3335
let y = next !z
3436
if safe !z y then
@@ -37,6 +39,7 @@ let digits =
3739
else
3840
z := (comp !z <| lfts())
3941
digits()
42+
4043
digits
4144

4245
let rec loop n s total =
@@ -53,5 +56,4 @@ let rec loop n s total =
5356

5457
loop 10 0 <| try
5558
int (System.Environment.GetCommandLineArgs().[1])
56-
with
57-
| _ -> 27
59+
with _ -> 27

tests/languageshootout_output/pidigits2.fs

+1-2
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,4 @@ let rec loop n s i z total =
4242

4343
loop 10 0 1I id <| try
4444
int (System.Environment.GetCommandLineArgs().[1])
45-
with
46-
| _ -> 27
45+
with _ -> 27

0 commit comments

Comments
 (0)