Skip to content

Commit

Permalink
add regression test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
ananthakumaran committed Oct 6, 2023
1 parent e247c6e commit 137ca34
Show file tree
Hide file tree
Showing 33 changed files with 2,625 additions and 12 deletions.
8 changes: 5 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
paisa.db
paisa.yaml
/paisa.yaml
/paisa
/sample
web/static
example.ledger
main.ledger
/example.ledger
/main.ledger
.DS_Store
node_modules
/build
Expand All @@ -18,3 +19,4 @@ vite.config.ts.timestamp-*
*.test
docs/lexer/__pycache__/
bun.lockb
svg/*
12 changes: 10 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,16 @@ lint:
npm run check
test -z $$(gofmt -l .)

test:
npm run test
regen:
go build
REGENERATE=true TZ=UTC bun test tests

jstest:
bun test --preload ./src/happydom.ts src
go build
TZ=UTC bun test tests

test: jstest
npm run build
go test ./...

Expand Down
2 changes: 0 additions & 2 deletions bunfig.toml

This file was deleted.

22 changes: 20 additions & 2 deletions internal/server/expense.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package server

import (
"sort"
"strings"

"github.com/ananthakumaran/paisa/internal/model/posting"
Expand Down Expand Up @@ -49,8 +50,8 @@ func GetExpense(db *gorm.DB) gin.H {
graph := make(map[string]map[string]Graph)
for fy, ps := range utils.GroupByFY(postings) {
graph[fy] = make(map[string]Graph)
graph[fy]["flat"] = computeGraph(ps)
graph[fy]["hierarchy"] = computeHierarchyGraph(ps)
graph[fy]["flat"] = sortGraph(computeGraph(ps))
graph[fy]["hierarchy"] = sortGraph(computeHierarchyGraph(ps))
}

return gin.H{
Expand All @@ -68,6 +69,23 @@ func GetExpense(db *gorm.DB) gin.H {
"graph": graph}
}

func sortGraph(graph Graph) Graph {
nodes := graph.Nodes
sort.Slice(nodes, func(i, j int) bool {
return graph.Nodes[i].Name < graph.Nodes[j].Name
})

links := graph.Links
sort.Slice(links, func(i, j int) bool {
return graph.Links[i].Source < graph.Links[j].Source || (graph.Links[i].Source == graph.Links[j].Source && graph.Links[i].Target < graph.Links[j].Target)
})
return Graph{
Nodes: nodes,
Links: links,
}

}

func computeGraph(postings []posting.Posting) Graph {
nodes := make(map[string]Node)
links := make(map[Pair]decimal.Decimal)
Expand Down
Loading

0 comments on commit 137ca34

Please sign in to comment.