Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ jobs:

- name: Build
run: go build -v ./...

- name: Test
run: go test -v ./...
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/spf13/afero v1.2.2 // indirect
github.com/spf13/cobra v1.1.3
github.com/spf13/viper v1.7.1
github.com/stretchr/testify v1.6.1 // indirect
github.com/stretchr/testify v1.6.1
github.com/superoo7/go-gecko v1.0.0
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
golang.org/x/sys v0.0.0-20210503173754-0981d6026fa6 // indirect
Expand Down
134 changes: 134 additions & 0 deletions pkg/display/allcoin/allCoin_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
/*
Copyright © 2021 Bhargav SNV bhargavsnv100@gmail.com

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package allcoin

import (
"sync"
"testing"

"github.com/stretchr/testify/assert"
)

func TestFilterRows(t *testing.T) {
tests := []struct {
allRows [][]string
filter string
filteredRows [][]string
}{
{
allRows: [][]string{
{"", "BTC", "", "", "", "bitcoin"},
{"", "ETH", "", "", "", "ethereum"},
{"", "LTC", "", "", "", "litecoin"},
{"", "BTC", "", "", "", "bitcoin"},
{"", "BTC", "", "", "", "bitcoin"},
},
filter: "bitcoin",
filteredRows: [][]string{
{"", "BTC", "", "", "", "bitcoin"},
{"", "BTC", "", "", "", "bitcoin"},
{"", "BTC", "", "", "", "bitcoin"},
},
},
{
allRows: [][]string{
{"", "BTC", "", "", "", "bitcoin"},
{"", "ETH", "", "", "", "ethereum"},
{"", "LTC", "", "", "", "litecoin"},
{"", "BTC", "", "", "", "bitcoin"},
{"", "BTC", "", "", "", "bitcoin"},
},
filter: "LTC",
filteredRows: [][]string{
{"", "LTC", "", "", "", "litecoin"},
},
},
{
allRows: [][]string{
{"", "XRP", "", "", "", "ripple"},
{"", "ETH", "", "", "", "ethereum"},
{"", "LTC", "", "", "", "litecoin"},
{"", "BTC", "", "", "", "bitcoin"},
},
filter: "ABA",
filteredRows: [][]string{},
},
{
allRows: [][]string{
{"", "XRP", "", "", "", "ripple"},
{"", "ETH", "", "", "", "ethereum"},
{"", "LTC", "", "", "", "litecoin"},
{"", "BTC", "", "", "", "bitcoin"},
{"", "XRP", "", "", "", "ripple"},
},
filter: "ripple",
filteredRows: [][]string{
{"", "XRP", "", "", "", "ripple"},
{"", "XRP", "", "", "", "ripple"},
},
},
{
allRows: [][]string{
{"", "BNB", "", "", "", "binance"},
{"", "ETH", "", "", "", "ethereum"},
{"", "DOGE", "", "", "", "dogecoin"},
{"", "BTC", "", "", "", "bitcoin"},
{"", "XRP", "", "", "", "ripple"},
},
filter: "dogecoin",
filteredRows: [][]string{
{"", "DOGE", "", "", "", "dogecoin"},
},
},
{
allRows: [][]string{
{"", "BNB", "", "", "", "binance"},
{"", "ETH", "", "", "", "ethereum"},
{"", "BTC", "", "", "", "bitcoin"},
{"", "XRP", "", "", "", "ripple"},
},
filter: "dogecoin",
filteredRows: [][]string{},
},
{
allRows: [][]string{},
filter: "litecoin",
filteredRows: [][]string{},
},
{
allRows: [][]string{
{"", "BNB", "", "", "", "binance"},
{"", "ETH", "", "", "", "ethereum"},
{"", "BTC", "", "", "", "bitcoin"},
{"", "XRP", "", "", "", "ripple"},
},
filter: "",
filteredRows: [][]string{
{"", "BNB", "", "", "", "binance"},
{"", "ETH", "", "", "", "ethereum"},
{"", "BTC", "", "", "", "bitcoin"},
{"", "XRP", "", "", "", "ripple"},
},
},
}

for _, test := range tests {
var mutex = &sync.Mutex{}
filteredRows := filterRows(test.allRows, test.filter, mutex)
assert.Equal(t, test.filteredRows, filteredRows)
}
}
2 changes: 1 addition & 1 deletion pkg/display/utilitywidgets/currency.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type CurrencyTable struct {
IDMap *CurrencyIDMap
}

// Currency holds information of a single currency, it used to populate currencyIDMaps
// CurrencyValue holds information of a single currency, it used to populate currencyIDMaps
type CurrencyValue struct {
Symbol string
RateUSD float64
Expand Down
7 changes: 7 additions & 0 deletions pkg/display/utilitywidgets/utility.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,20 @@ limitations under the License.

package utilitywidgets

// Utility represents a utilty displayed in the UI
type Utility int

const (
// None is when no utility is being displayed and the page is visible
None Utility = iota
// Help is when the help table is displayed
Help
// Portfolio is when the mini portfolio table is displayed
Portfolio
// Change is when the change interval table is displayed
Change
// Duration is when the graph duration interval table is displayed
Duration
// Currency is when the currency selection table is displayed
Currency
)
126 changes: 126 additions & 0 deletions pkg/utils/utils_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/*
Copyright © 2021 Bhargav SNV bhargavsnv100@gmail.com

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package utils_test

import (
"testing"

"github.com/Gituser143/cryptgo/pkg/utils"
"github.com/stretchr/testify/assert"
)

func TestMinFloat64(t *testing.T) {
tests := []struct {
inputVal []float64
expectedVal float64
}{
{
inputVal: []float64{10, 20, 30, 40},
expectedVal: 10,
},
{
inputVal: []float64{},
expectedVal: 0,
},
{
inputVal: []float64{-10, 20, -30, 40},
expectedVal: -30,
},
}

for _, test := range tests {
val := utils.MinFloat64(test.inputVal...)
assert.Equal(t, test.expectedVal, val)
}
}

func TestMaxFloat64(t *testing.T) {
tests := []struct {
inputVal []float64
expectedVal float64
}{
{
inputVal: []float64{10, 20, 30, 40},
expectedVal: 40,
},
{
inputVal: []float64{},
expectedVal: 0,
},
{
inputVal: []float64{-10, -20, -30, -40},
expectedVal: -10,
},
}

for _, test := range tests {
val := utils.MaxFloat64(test.inputVal...)
assert.Equal(t, test.expectedVal, val)
}
}

func TestRoundValues(t *testing.T) {
tests := []struct {
name string
inputNum1 float64
inputNum2 float64
expRoundedVals []float64
expUnit string
}{
{
name: "both values smaller than kilo",
inputNum1: 250,
inputNum2: 500,
expRoundedVals: []float64{250, 500},
expUnit: "",
},
{
name: "both values kilo",
inputNum1: 80000,
inputNum2: 9000,
expRoundedVals: []float64{80, 9},
expUnit: "K",
},
{
name: "mega and less than mega",
inputNum1: 400000,
inputNum2: 7000000,
expRoundedVals: []float64{0.4, 7},
expUnit: "M",
},
{
name: "giga and less than giga",
inputNum1: 100000000,
inputNum2: 9000000000,
expRoundedVals: []float64{0.1, 9},
expUnit: "B",
},
{
name: "both values tera",
inputNum1: 5000000000000000,
inputNum2: 100000000000000,
expRoundedVals: []float64{5000, 100},
expUnit: "T",
},
}

for _, test := range tests {
roundedVals, unit := utils.RoundValues(test.inputNum1, test.inputNum2)
assert.Equal(t, test.expRoundedVals, roundedVals)
assert.Equal(t, test.expUnit, unit)
}
}