Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
satellite/emission: refactor dimension handling logic
Make dimension handling more efficient. It avoids the string manipulation and removes the need for simplify. Resolves post-merge comment of #12318 Issue: #6694 Change-Id: Ic5d802afbec4f9e92e35dd660b30c517e3af32b8
- Loading branch information
1 parent
11b4095
commit 7d3c13c
Showing
3 changed files
with
223 additions
and
241 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright (C) 2024 Storj Labs, Inc. | ||
// See LICENSE for copying information. | ||
|
||
package emission | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestUnit_String(t *testing.T) { | ||
cases := []struct { | ||
unit Unit | ||
expected string | ||
}{ | ||
{unit: Unit{}, expected: ""}, | ||
{unit: Unit{byte: 1}, expected: "B"}, | ||
{unit: Unit{watt: 1}, expected: "W"}, | ||
{unit: Unit{hour: 1}, expected: "H"}, | ||
{unit: Unit{hour: -1}, expected: "1/H"}, | ||
{unit: Unit{kilogram: 1}, expected: "kg"}, | ||
{unit: Unit{kilogram: -1}, expected: "1/kg"}, | ||
{unit: Unit{byte: 1, watt: 1}, expected: "BW"}, | ||
{unit: Unit{byte: 1, watt: -1}, expected: "B/W"}, | ||
{unit: Unit{byte: 1, watt: -1, hour: -1}, expected: "B/WH"}, | ||
{unit: Unit{byte: 1, kilogram: 1, watt: -1, hour: -1}, expected: "Bkg/WH"}, | ||
{unit: Unit{byte: 2, kilogram: 1, watt: -2, hour: -1}, expected: "B²kg/W²H"}, | ||
{unit: Unit{byte: 3, watt: -1, hour: -2}, expected: "B³/WH²"}, | ||
{unit: Unit{byte: 2, watt: -4, hour: -1}, expected: "B²/W^4H"}, | ||
} | ||
|
||
for _, c := range cases { | ||
t.Run(fmt.Sprintf("expected:%s", c.expected), func(t *testing.T) { | ||
require.Equal(t, c.unit.String(), c.expected) | ||
}) | ||
} | ||
} |
Oops, something went wrong.