• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

HDT3213 / godis / 4797094592

25 Apr 2023 11:50AM UTC coverage: 75.847% (+0.03%) from 75.813%
4797094592

push

github

finley
fix Error()

6224 of 8206 relevant lines covered (75.85%)

0.85 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

23.91
/datastruct/sortedset/border.go
1
package sortedset
2

3
import (
4
        "errors"
5
        "strconv"
6
)
7

8
/*
9
 * ScoreBorder is a struct represents `min` `max` parameter of redis command `ZRANGEBYSCORE`
10
 * can accept:
11
 *   int or float value, such as 2.718, 2, -2.718, -2 ...
12
 *   exclusive int or float value, such as (2.718, (2, (-2.718, (-2 ...
13
 *   infinity: +inf, -inf, inf(same as +inf)
14
 */
15

16
const (
17
        negativeInf int8 = -1
18
        positiveInf int8 = 1
19
)
20

21
// ScoreBorder represents range of a float value, including: <, <=, >, >=, +inf, -inf
22
type ScoreBorder struct {
23
        Inf     int8
24
        Value   float64
25
        Exclude bool
26
}
27

28
// if max.greater(score) then the score is within the upper border
29
// do not use min.greater()
30
func (border *ScoreBorder) greater(value float64) bool {
1✔
31
        if border.Inf == negativeInf {
1✔
32
                return false
×
33
        } else if border.Inf == positiveInf {
2✔
34
                return true
1✔
35
        }
1✔
36
        if border.Exclude {
×
37
                return border.Value > value
×
38
        }
×
39
        return border.Value >= value
×
40
}
41

42
func (border *ScoreBorder) less(value float64) bool {
1✔
43
        if border.Inf == negativeInf {
2✔
44
                return true
1✔
45
        } else if border.Inf == positiveInf {
2✔
46
                return false
×
47
        }
×
48
        if border.Exclude {
1✔
49
                return border.Value < value
×
50
        }
×
51
        return border.Value <= value
1✔
52
}
53

54
var positiveInfBorder = &ScoreBorder{
55
        Inf: positiveInf,
56
}
57

58
var negativeInfBorder = &ScoreBorder{
59
        Inf: negativeInf,
60
}
61

62
// ParseScoreBorder creates ScoreBorder from redis arguments
63
func ParseScoreBorder(s string) (*ScoreBorder, error) {
×
64
        if s == "inf" || s == "+inf" {
×
65
                return positiveInfBorder, nil
×
66
        }
×
67
        if s == "-inf" {
×
68
                return negativeInfBorder, nil
×
69
        }
×
70
        if s[0] == '(' {
×
71
                value, err := strconv.ParseFloat(s[1:], 64)
×
72
                if err != nil {
×
73
                        return nil, errors.New("ERR min or max is not a float")
×
74
                }
×
75
                return &ScoreBorder{
×
76
                        Inf:     0,
×
77
                        Value:   value,
×
78
                        Exclude: true,
×
79
                }, nil
×
80
        }
81
        value, err := strconv.ParseFloat(s, 64)
×
82
        if err != nil {
×
83
                return nil, errors.New("ERR min or max is not a float")
×
84
        }
×
85
        return &ScoreBorder{
×
86
                Inf:     0,
×
87
                Value:   value,
×
88
                Exclude: false,
×
89
        }, nil
×
90
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc