Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit tests #28

Merged
merged 4 commits into from
Oct 3, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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 ./...
77 changes: 77 additions & 0 deletions pkg/display/allcoin/allCoin_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
Copyright © 2021 Bhargav SNV [email protected]

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"},
},
Gituser143 marked this conversation as resolved.
Show resolved Hide resolved
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{},
},
}

for _, test := range tests {
var mutex = &sync.Mutex{}
filteredRows := filterRows(test.allRows, test.filter, mutex)
assert.Equal(t, test.filteredRows, filteredRows)
}
}
52 changes: 52 additions & 0 deletions pkg/utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,55 @@ func TestMaxFloat64(t *testing.T) {
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)
}
}