Skip to content

Commit

Permalink
Merge pull request #104 from a4abhishek/fixes-unreachable-code-and-fo…
Browse files Browse the repository at this point in the history
…rmat-issues

Minor improvement in code quality
  • Loading branch information
technosophos authored Jul 25, 2018
2 parents a5fa5b8 + 5834241 commit 7512e63
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 27 deletions.
1 change: 0 additions & 1 deletion defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ func empty(given interface{}) bool {
case reflect.Struct:
return false
}
return true
}

// coalesce returns the first non-empty value.
Expand Down
2 changes: 1 addition & 1 deletion numeric.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,4 @@ func round(a interface{}, p int, r_opt ...float64) float64 {
round = math.Floor(digit)
}
return round / pow
}
}
6 changes: 3 additions & 3 deletions numeric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,21 +181,21 @@ func TestMul(t *testing.T) {
}
}

func TestCeil(t *testing.T){
func TestCeil(t *testing.T) {
assert.Equal(t, 123.0, ceil(123))
assert.Equal(t, 123.0, ceil("123"))
assert.Equal(t, 124.0, ceil(123.01))
assert.Equal(t, 124.0, ceil("123.01"))
}

func TestFloor(t *testing.T){
func TestFloor(t *testing.T) {
assert.Equal(t, 123.0, floor(123))
assert.Equal(t, 123.0, floor("123"))
assert.Equal(t, 123.0, floor(123.9999))
assert.Equal(t, 123.0, floor("123.9999"))
}

func TestRound(t *testing.T){
func TestRound(t *testing.T) {
assert.Equal(t, 123.556, round(123.5555, 3))
assert.Equal(t, 123.556, round("123.55555", 3))
assert.Equal(t, 124.0, round(123.500001, 0))
Expand Down
2 changes: 1 addition & 1 deletion regex.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ func regexReplaceAllLiteral(regex string, s string, repl string) string {
func regexSplit(regex string, s string, n int) []string {
r := regexp.MustCompile(regex)
return r.Split(s, n)
}
}
42 changes: 21 additions & 21 deletions regex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,46 +16,46 @@ func TestRegexMatch(t *testing.T) {
assert.False(t, regexMatch(regex, "test@acme"))
}

func TestRegexFindAll(t *testing.T){
func TestRegexFindAll(t *testing.T) {
regex := "a{2}"
assert.Equal(t, 1, len(regexFindAll(regex, "aa", -1)))
assert.Equal(t, 1, len(regexFindAll(regex, "aaaaaaaa", 1)))
assert.Equal(t, 2, len(regexFindAll(regex, "aaaa", -1)))
assert.Equal(t, 0, len(regexFindAll(regex, "none", -1)))
}

func TestRegexFindl(t *testing.T){
func TestRegexFindl(t *testing.T) {
regex := "fo.?"
assert.Equal(t, "foo", regexFind(regex, "foorbar"))
assert.Equal(t, "foo", regexFind(regex, "foo foe fome"))
assert.Equal(t, "", regexFind(regex, "none"))
}

func TestRegexReplaceAll(t *testing.T){
func TestRegexReplaceAll(t *testing.T) {
regex := "a(x*)b"
assert.Equal(t, "-T-T-", regexReplaceAll(regex,"-ab-axxb-", "T"))
assert.Equal(t, "--xx-", regexReplaceAll(regex,"-ab-axxb-", "$1"))
assert.Equal(t, "---", regexReplaceAll(regex,"-ab-axxb-", "$1W"))
assert.Equal(t, "-W-xxW-", regexReplaceAll(regex,"-ab-axxb-", "${1}W"))
assert.Equal(t, "-T-T-", regexReplaceAll(regex, "-ab-axxb-", "T"))
assert.Equal(t, "--xx-", regexReplaceAll(regex, "-ab-axxb-", "$1"))
assert.Equal(t, "---", regexReplaceAll(regex, "-ab-axxb-", "$1W"))
assert.Equal(t, "-W-xxW-", regexReplaceAll(regex, "-ab-axxb-", "${1}W"))
}

func TestRegexReplaceAllLiteral(t *testing.T){
func TestRegexReplaceAllLiteral(t *testing.T) {
regex := "a(x*)b"
assert.Equal(t, "-T-T-", regexReplaceAllLiteral(regex,"-ab-axxb-", "T"))
assert.Equal(t, "-$1-$1-", regexReplaceAllLiteral(regex,"-ab-axxb-", "$1"))
assert.Equal(t, "-${1}-${1}-", regexReplaceAllLiteral(regex,"-ab-axxb-", "${1}"))
assert.Equal(t, "-T-T-", regexReplaceAllLiteral(regex, "-ab-axxb-", "T"))
assert.Equal(t, "-$1-$1-", regexReplaceAllLiteral(regex, "-ab-axxb-", "$1"))
assert.Equal(t, "-${1}-${1}-", regexReplaceAllLiteral(regex, "-ab-axxb-", "${1}"))
}

func TestRegexSplit(t *testing.T){
func TestRegexSplit(t *testing.T) {
regex := "a"
assert.Equal(t, 4, len(regexSplit(regex,"banana", -1)))
assert.Equal(t, 0, len(regexSplit(regex,"banana", 0)))
assert.Equal(t, 1, len(regexSplit(regex,"banana", 1)))
assert.Equal(t, 2, len(regexSplit(regex,"banana", 2)))
assert.Equal(t, 4, len(regexSplit(regex, "banana", -1)))
assert.Equal(t, 0, len(regexSplit(regex, "banana", 0)))
assert.Equal(t, 1, len(regexSplit(regex, "banana", 1)))
assert.Equal(t, 2, len(regexSplit(regex, "banana", 2)))

regex = "z+"
assert.Equal(t, 2, len(regexSplit(regex,"pizza", -1)))
assert.Equal(t, 0, len(regexSplit(regex,"pizza", 0)))
assert.Equal(t, 1, len(regexSplit(regex,"pizza", 1)))
assert.Equal(t, 2, len(regexSplit(regex,"pizza", 2)))
}
assert.Equal(t, 2, len(regexSplit(regex, "pizza", -1)))
assert.Equal(t, 0, len(regexSplit(regex, "pizza", 0)))
assert.Equal(t, 1, len(regexSplit(regex, "pizza", 1)))
assert.Equal(t, 2, len(regexSplit(regex, "pizza", 2)))
}

0 comments on commit 7512e63

Please sign in to comment.