MCPcopy Create free account
hub / github.com/devaccuracy/ledgerforge / TestCalculateDistributionsPrecise

Function TestCalculateDistributionsPrecise

model/transaction_test.go:65–221  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

63}
64
65func TestCalculateDistributionsPrecise(t *testing.T) {
66 tests := []struct {
67 name string
68 totalAmount float64
69 precision int64
70 distributions []Distribution
71 want map[string]float64
72 wantErr bool
73 }{
74 {
75 name: "Fixed and Percentage",
76 totalAmount: 1000,
77 precision: 100,
78 distributions: []Distribution{
79 {Identifier: "A", Distribution: "200"}, // Fixed amount
80 {Identifier: "B", Distribution: "50%"}, // Percentage
81 {Identifier: "C", Distribution: "left"}, // Leftover
82 },
83 want: map[string]float64{
84 "A": 200, // Fixed
85 "B": 500, // 50% of 1000
86 "C": 300, // Leftover (1000 - 200 - 500)
87 },
88 wantErr: false,
89 },
90 {
91 name: "Ride Fee Distribution",
92 totalAmount: 1.5,
93 precision: 100,
94 distributions: []Distribution{
95 {Identifier: "@TaxiPay_REV", Distribution: "50%"},
96 {Identifier: "@B_REV", Distribution: "45%"},
97 {Identifier: "@Assoc_REV", Distribution: "left"},
98 },
99 want: map[string]float64{
100 "@TaxiPay_REV": 0.76, // 50% of 1.5
101 "@B_REV": 0.67, // 45% of 1.5
102 "@Assoc_REV": 0.07, // 5% of 1.5
103 },
104 wantErr: false,
105 },
106 {
107 name: "Multiple Fixed Amounts",
108 totalAmount: 1000,
109 precision: 100,
110 distributions: []Distribution{
111 {Identifier: "A", Distribution: "200"},
112 {Identifier: "B", Distribution: "300"},
113 {Identifier: "C", Distribution: "left"},
114 },
115 want: map[string]float64{
116 "A": 200,
117 "B": 300,
118 "C": 500,
119 },
120 wantErr: false,
121 },
122 {

Callers

nothing calls this directly

Calls 4

floatToBigIntFunction · 0.85
floatMapToBigIntMapFunction · 0.85
bigIntMapsEqualFunction · 0.85

Tested by

no test coverage detected