-
Notifications
You must be signed in to change notification settings - Fork 15
/
main_test.go
executable file
·112 lines (86 loc) · 2.91 KB
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// Copyright 2016 Patrick Brosi
// Authors: [email protected]
//
// Use of this source code is governed by a GPL v2
// license that can be found in the LICENSE file
package main
import (
"github.com/patrickbr/gtfsparser"
"github.com/patrickbr/gtfstidy/processors"
"github.com/patrickbr/gtfswriter"
"os"
"path"
"testing"
)
func TestGtfsTidy(t *testing.T) {
feed := gtfsparser.NewFeed()
opts := gtfsparser.ParseOptions{UseDefValueOnError: false, DropErroneous: false, DryRun: false, CheckNullCoordinates: false, EmptyStringRepl: "", ZipFix: false}
feed.SetParseOpts(opts)
e := feed.Parse("./processors/testfeed")
if e != nil {
t.Error(e)
return
}
minzers := make([]processors.Processor, 0)
minzers = append(minzers, processors.OrphanRemover{})
minzers = append(minzers, processors.ShapeRemeasurer{})
minzers = append(minzers, processors.ShapeMinimizer{Epsilon: 1.0})
minzers = append(minzers, processors.ShapeDuplicateRemover{MaxEqDist: 10.0})
minzers = append(minzers, processors.RouteDuplicateRemover{})
minzers = append(minzers, processors.ServiceDuplicateRemover{})
minzers = append(minzers, processors.ServiceMinimizer{})
minzers = append(minzers, processors.FrequencyMinimizer{})
minzers = append(minzers, processors.IDMinimizer{Base: 36})
for _, m := range minzers {
m.Run(feed)
}
outputPath := ".testout.zip"
if _, err := os.Stat(outputPath); os.IsNotExist(err) {
if path.Ext(outputPath) == ".zip" {
os.Create(outputPath)
} else {
os.Mkdir(outputPath, os.ModePerm)
}
}
// write feed back to output
w := gtfswriter.Writer{ZipCompressionLevel: 9, Sorted: true}
e = w.Write(feed, outputPath)
if e != nil {
t.Error(e)
return
}
feed = gtfsparser.NewFeed()
opts = gtfsparser.ParseOptions{UseDefValueOnError: false, DropErroneous: false, DryRun: true, CheckNullCoordinates: false, EmptyStringRepl: "", ZipFix: false}
feed.SetParseOpts(opts)
e = feed.Parse(".testout.zip")
if e != nil {
t.Error(e)
return
}
feed = gtfsparser.NewFeed()
opts = gtfsparser.ParseOptions{UseDefValueOnError: false, DropErroneous: false, DryRun: true, CheckNullCoordinates: false, EmptyStringRepl: "", ZipFix: false}
feed.SetParseOpts(opts)
e = feed.Parse("./processors/testfeed-err")
if e == nil {
t.Error("No errors found.")
return
}
opts = gtfsparser.ParseOptions{UseDefValueOnError: true, DropErroneous: true, DryRun: false, CheckNullCoordinates: false, EmptyStringRepl: "", ZipFix: false}
feed.SetParseOpts(opts)
// write feed back to output
w = gtfswriter.Writer{ZipCompressionLevel: 9, Sorted: true}
e = w.Write(feed, outputPath)
if e != nil {
t.Error(e)
return
}
feed = gtfsparser.NewFeed()
opts = gtfsparser.ParseOptions{UseDefValueOnError: false, DropErroneous: false, DryRun: true, CheckNullCoordinates: false, EmptyStringRepl: "", ZipFix: false}
feed.SetParseOpts(opts)
e = feed.Parse(".testout.zip")
if e != nil {
t.Error(e)
return
}
os.Remove(".testout.zip")
}