Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(6)

Side by Side Diff: testing/checkers/relop.go

Issue 10395044: Some useful checkers.
Patch Set: Some useful checkers. Created 11 years, 9 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2013 Canonical Ltd.
2 // Licensed under the AGPLv3, see LICENCE file for details.
3
4 package checkers
5
6 import (
7 "fmt"
8 "reflect"
9
10 . "launchpad.net/gocheck"
11 )
12
13 // GreaterThan checker
14
15 type greaterThanChecker struct {
16 *CheckerInfo
17 }
18
19 var GreaterThan Checker = &greaterThanChecker{
20 &CheckerInfo{Name: "GreaterThan", Params: []string{"obtained", "expected "}},
21 }
22
23 func (checker *greaterThanChecker) Check(params []interface{}, names []string) ( result bool, error string) {
24 defer func() {
25 if v := recover(); v != nil {
26 result = false
27 error = fmt.Sprint(v)
28 }
29 }()
30
31 p0value := reflect.ValueOf(params[0])
32 p1value := reflect.ValueOf(params[1])
33 switch p0value.Kind() {
34 case reflect.Int,
35 reflect.Int8,
36 reflect.Int16,
37 reflect.Int32,
38 reflect.Int64:
39 return p0value.Int() > p1value.Int(), ""
40 case reflect.Uint,
41 reflect.Uint8,
42 reflect.Uint16,
43 reflect.Uint32,
44 reflect.Uint64:
45 return p0value.Uint() > p1value.Uint(), ""
46 case reflect.Float32,
47 reflect.Float64:
48 return p0value.Float() > p1value.Float(), ""
49 default:
50 }
51 return false, fmt.Sprintf("obtained value %s:%#v not supported", p0value .Kind(), params[0])
rog 2013/06/19 11:19:05 fmt.Sprintf("expected numeric type, received %T",
52 }
OLDNEW

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b