-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First pass at implementing log10/2 scale (#97)
Add log10/2 scale. Resolves #96
- Loading branch information
Showing
15 changed files
with
423 additions
and
81 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 |
---|---|---|
@@ -1,10 +1,28 @@ | ||
package cmd | ||
|
||
import "testing" | ||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestHeatmap(t *testing.T) { | ||
testCommandSet(t, heatmapCommand(), | ||
`-m "(.+) (\d+)" -e "{$ {1} {2}}" testdata/graph.txt`, | ||
`-o - -m "(.+) (\d+)" -e "{$ {1} {2}}" testdata/graph.txt`, | ||
) | ||
} | ||
|
||
func TestHeatmapLinear(t *testing.T) { | ||
out, eout, err := testCommandCapture(heatmapCommand(), `--snapshot -m "(.+) (.+)" -e "{$ {1} {2}}" testdata/heat.txt`) | ||
assert.NoError(t, err) | ||
assert.Empty(t, eout) | ||
assert.Equal(t, " - 0 2 1 4 2 6 3 9 4\n a..\nx -22\ny 224\nz 9--\nMatched: 10 / 10 (R: 3; C: 3)\n39 B (0 B/s) \n", out) | ||
} | ||
|
||
func TestHeatmapLog2(t *testing.T) { | ||
out, eout, err := testCommandCapture(heatmapCommand(), `--snapshot -m "(.+) (.+)" -e "{$ {1} {2}}" --scale log2 testdata/heat.txt`) | ||
assert.NoError(t, err) | ||
assert.Empty(t, eout) | ||
assert.Equal(t, " - 1 4 2 7 3 9 4\n a..\nx ---\ny --4\nz 9--\nMatched: 10 / 10 (R: 3; C: 3)\n39 B (0 B/s) \n", out) | ||
} |
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
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,33 @@ | ||
package helpers | ||
|
||
import ( | ||
"errors" | ||
"rare/pkg/logger" | ||
"rare/pkg/multiterm/termscaler" | ||
|
||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
var ScaleFlag = &cli.StringFlag{ | ||
Name: "scale", | ||
Usage: "Defines data-scaling (linear, log10, log2)", | ||
Value: "linear", | ||
} | ||
|
||
func BuildScaler(scalerName string) (termscaler.Scaler, error) { | ||
if scalerName == "" { | ||
return termscaler.ScalerLinear, nil | ||
} | ||
if scaler, ok := termscaler.ScalerByName(scalerName); ok { | ||
return scaler, nil | ||
} | ||
return termscaler.ScalerNull, errors.New("invalid scaler") | ||
} | ||
|
||
func BuildScalerOrFail(scalerName string) termscaler.Scaler { | ||
s, err := BuildScaler(scalerName) | ||
if err != nil { | ||
logger.Fatal(err) | ||
} | ||
return s | ||
} |
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,23 @@ | ||
package helpers | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestBuildScaler(t *testing.T) { | ||
_, err := BuildScaler("") | ||
assert.NoError(t, err) | ||
|
||
_, err = BuildScaler("log10") | ||
assert.NoError(t, err) | ||
|
||
_, err = BuildScaler("bad-data") | ||
assert.Error(t, err) | ||
} | ||
|
||
func TestBuildScalerOrFail(t *testing.T) { | ||
assert.NotNil(t, BuildScalerOrFail("")) | ||
assert.NotNil(t, BuildScalerOrFail("linear")) | ||
} |
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,10 @@ | ||
a y | ||
a z | ||
a z | ||
a z | ||
a z | ||
b y | ||
b x | ||
c y | ||
c x | ||
c y |
Binary file not shown.
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
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
Oops, something went wrong.