comparison

package
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 8, 2022 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TypeNames = map[Type]string{
	TypeValue:      "comparison_value",
	TypePercentage: "comparison_percentage",
}

TypeNames maps a comparison.Type to its string form.

Functions

This section is empty.

Types

type Comparator

type Comparator interface {
	Compare(lhs, rhs float64) bool
	Operator() Operator
}

Comparator is an interface that all comparators must implement

type Eq

type Eq struct {
}

Eq implements an "equal" comparator

func (Eq) Compare

func (c Eq) Compare(lhs, rhs float64) bool

Compare implement the "equal" comparison

func (Eq) Operator

func (c Eq) Operator() Operator

Operator returns the operator applied during the comparison

type Expression

type Expression struct {
	Type Type
	Cmp  Comparator
	RHS  float64
	// contains filtered or unexported fields
}

Expression is a struct that represents the deserialization of a string expression. The deserialization includes the following: * The comparison type (absolute, relative) * The comparison function and operator * The right hand side operator

func ParseExpression

func ParseExpression(expression string) (*Expression, error)

ParseExpression deserializes a string comparison expression (e.g. "">=50") into a Expression object. Returns an error if the expression is not supported.

func (Expression) EvaluateSuccess

func (e Expression) EvaluateSuccess(success, total uint64) (*Result, error)

EvaluateSuccess invokes the Compare function of the internal Comparator object

func (Expression) String

func (e Expression) String() string

type Ge

type Ge struct {
}

Ge implements a "greater or equal" comparator

func (Ge) Compare

func (c Ge) Compare(lhs, rhs float64) bool

Compare implement the "greater or equal" comparison

func (Ge) Operator

func (c Ge) Operator() Operator

Operator returns the operator applied during the comparison

type Gt

type Gt struct {
}

Gt implements a "greater than" comparator

func (Gt) Compare

func (c Gt) Compare(lhs, rhs float64) bool

Compare implement the "greater than" comparison

func (Gt) Operator

func (c Gt) Operator() Operator

Operator returns the operator applied during the comparison

type Le

type Le struct {
}

Le implements a "less or equal" comparator

func (Le) Compare

func (c Le) Compare(lhs, rhs float64) bool

Compare implement the "less or equal" comparison

func (Le) Operator

func (c Le) Operator() Operator

Operator returns the operator applied during the comparison

type Lt

type Lt struct {
}

Lt implements a "less than" comparator

func (Lt) Compare

func (c Lt) Compare(lhs, rhs float64) bool

Compare implement the "less than" comparison

func (Lt) Operator

func (c Lt) Operator() Operator

Operator returns the operator applied during the comparison

type Operator

type Operator string

Operator is the string representation of any of the supported comparison operators

const (
	ExprGt Operator = ">"
	ExprLt Operator = "<"
	ExprGe Operator = ">="
	ExprLe Operator = "<="
	ExprEq Operator = "="
)

comparison operators.

type Result

type Result struct {
	Pass bool
	Expr string
	LHS  string
	RHS  string
	Type Type
	Op   Operator
}

Result wraps the result of a comparison, including the full expression that was evaluated

type Type

type Type uint16

Type represents the type of comparison. It could be an absolute (e.g. >50) or relative comparison (e.g. >50%)

const (
	TypeValue Type = iota
	TypePercentage
)

List of possible comparison types

func (Type) String

func (t Type) String() string

String translates a Type object into its corresponding string representation

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL