2017-11-02 07:05:11 -07:00

478 lines
11 KiB
YAML

desc: Tests of comparison operators
tests:
### Numeric comparisons
## basic <
- cd: r(1).lt(2)
py:
- r.expr(1) < 2
- 1 < r.expr(2)
- r.expr(1).lt(2)
rb:
- r(1) < 2
- r(1).lt(2)
- 1 < r(2)
ot: true
- cd: r(3).lt(2)
py: r.expr(3) < 2
rb: r(3) < 2
ot: false
- py: r.expr(2) < 2
js: r(2).lt(2)
rb: r(2) < 2
ot: false
# All Comparisons can take an arbitrary number of arguments though
# the functionality is only available in JS at the moment
- js: r(1).lt(2, 3, 4)
ot: true
- js: r(1).lt(2, 3, 2)
ot: false
## basic >
- cd: r(1).gt(2)
py:
- r.expr(1) > 2
- 1 > r.expr(2)
- r.expr(1).gt(2)
rb:
- r(1) > 2
- r(1).gt(2)
ot: false
- py: r.expr(3) > 2
js: r(3).gt(2)
rb: r(3) > 2
ot: true
- py: r.expr(2) > 2
js: r(2).gt(2)
rb: r(2) > 2
ot: false
- js: r(4).gt(3, 2, 1)
ot: true
- js: r(4).gt(3, 2, 3)
ot: false
## basic ==
- cd: r(1).eq(2)
py:
- r.expr(1) == 2
- 1 == r.expr(2)
- r.expr(1).eq(2)
rb: r(1).eq 2
ot: false
- py: r.expr(3) == 2
js: r(3).eq(2)
rb: r(3).eq 2
ot: false
- py: r.expr(2) == 2
js: r(2).eq(2)
rb: r(2).eq 2
ot: true
- js: r(1).eq(1, 1, 1)
ot: true
- js: r(1).eq(1, 2, 1)
ot: false
## basic !=
- cd: r(1).ne(2)
py:
- r.expr(1) != 2
- 1 != r.expr(2)
- r.expr(1).ne(2)
rb: r(1).ne 2
ot: true
- py: r.expr(3) != 2
js: r(3).ne(2)
rb: r(3).ne 2
ot: true
- py: r.expr(2) != 2
js: r(2).ne(2)
rb: r(2).ne 2
ot: false
- js: r(1).ne(3, 2, 4)
ot: true
- js: r(1).ne(3, 2, 3)
ot: true
## basic <=
- js: r(1).le(2)
py:
- r.expr(1) <= 2
- 1 <= r.expr(2)
- r.expr(1).le(2)
rb:
- r(1) <= 2
- r(1).le(2)
ot: true
- py: r.expr(3) <= 2
js: r(3).le(2)
rb: r(3) <= 2
ot: false
- py: r.expr(2) <= 2
js: r(2).le(2)
rb: r(2) <= 2
ot: true
- js: r(1).le(1, 2, 2)
ot: true
- js: r(1).le(1, 3, 2)
ot: false
## basic >=
- cd: r(1).ge(2)
py:
- r.expr(1) >= 2
- 1 >= r.expr(2)
- r.expr(1).ge(2)
rb:
- r(1) >= 2
- r(1).ge(2)
ot: false
- py: r.expr(3) >= 2
js: r(3).ge(2)
rb: r(3) >= 2
ot: true
- py: r.expr(2) >= 2
js: r(2).ge(2)
rb: r(2) >= 2
ot: true
- js: r(4).ge(4, 2, 2)
ot: true
- js: r(4).ge(4, 2, 3)
ot: false
# Comparisons for NULL
- cd: r(null).eq(null)
py:
- r.expr(null) == null
- null == r.expr(null)
ot: true
- cd: r(null).lt(null)
py:
- r.expr(null) < null
- null < r.expr(null)
- r.expr(null).lt(null)
rb: r(null) < null
ot: false
- cd: r(null).gt(null)
py:
- r.expr(null) > null
- null > r.expr(null)
- r.expr(null).gt(null)
rb: r(null) > null
ot: false
# Comparisons for STRING
# STRING comparison should be lexicagraphical
- py: r.expr('a') == 'a'
cd: r('a').eq('a')
ot: true
- py: r.expr('a') == 'aa'
cd: r('a').eq('aa')
ot: false
- py: r.expr('a') < 'aa'
cd: r('a').lt('aa')
ot: true
- py: r.expr('a') < 'bb'
cd: r('a').lt('bb')
ot: true
- py: r.expr('bb') > 'a'
cd: r('bb').gt('a')
ot: true
- py: r.expr('abcdef') < 'abcdeg'
cd: r('abcdef').lt('abcdeg')
ot: true
- py: r.expr('abcdefg') > 'abcdeg'
cd: r('abcdefg').gt('abcdeg')
ot: false
- py: r.expr('A quick brown fox') > 'A quick brawn fox'
js: r('A quick brown fox').gt('A quick brawn fox')
rb: r('A quick brown fox') > 'A quick brawn fox'
ot: true
# Comparisons for ARRAY
# Also lexicographical
- py: r.expr([1]) < [2]
js: r([1]).lt([2])
rb: r([1]) < [2]
ot: true
- py: r.expr([1]) > [2]
js: r([1]).gt([2])
rb: r([1]) > [2]
ot: false
- py: r.expr([1, 0]) < [2]
js: r([1, 0]).lt([2])
rb: r([1, 0]) < [2]
ot: true
- py: r.expr([1, 0]) < [1]
js: r([1, 0]).lt([1])
rb: r([1, 0]) < [1]
ot: false
- py: r.expr([1, 0]) > [0]
js: r([1, 0]).gt([0])
rb: r([1, 0]) > [0]
ot: true
- py: r.expr([1, 'a']) < [1, 'b']
js: r([1, 'a']).lt([1, 'b'])
rb: r([1, 'a']) < [1, 'b']
ot: true
- py: r.expr([0, 'z']) < [1, 'b']
js: r([0, 'z']).lt([1, 'b'])
rb: r([0, 'z']) < [1, 'b']
ot: true
- py: r.expr([1, 1, 1]) < [1, 0, 2]
js: r([1, 1, 1]).lt([1, 0, 2])
rb: r([1, 1, 1]) < [1, 0, 2]
ot: false
- py: r.expr([1, 0, 2]) < [1, 1, 1]
js: r([1, 0, 2]).lt([1, 1, 1])
rb: r([1, 0, 2]) < [1, 1, 1]
ot: true
# Comparisons for OBJECT
- py: r.expr({'a':0}) == {'a':0}
cd: r({'a':0}).eq({'a':0})
ot: true
- py: r.expr({'a':0, 'b':1}) == {'b':1, 'a':0}
cd: r({'a':0, 'b':1}).eq({'b':1, 'a':0})
ot: true
- py: r.expr({'a':0, 'b':1, 'c':2}) == {'b':1, 'a':0}
cd: r({'a':0, 'b':1, 'c':2}).eq({'b':1, 'a':0})
ot: false
- py: r.expr({'a':0, 'b':1}) == {'b':1, 'a':0, 'c':2}
cd: r({'a':0, 'b':1}).eq({'b':1, 'a':0, 'c':2})
ot: false
- py: r.expr({'a':0, 'b':1, 'd':2}) == {'b':1, 'a':0, 'c':2}
cd: r({'a':0, 'b':1, 'd':2}).eq({'b':1, 'a':0, 'c':2})
ot: false
- py: r.expr({'a':0}) < {'b':0}
cd: r({'a':0}).lt({'b':0})
ot: true
- py: r.expr({'a':1}) < {'b':0}
cd: r({'a':1}).lt({'b':0})
ot: true
- py: r.expr({'b':1}) < {'b':0}
cd: r({'b':1}).lt({'b':0})
ot: false
- py: r.expr({'b':1}) < {'a':0}
cd: r({'b':1}).lt({'a':0})
ot: false
- py: r.expr({'a':0, 'b':1, 'c':2}) < {'a':0, 'b':1, 'c':2}
cd: r({'a':0, 'b':1, 'c':2}).lt({'a':0, 'b':1, 'c':2})
ot: false
- py: r.expr({'a':0, 'b':1, 'c':2, 'd':3}) < {'a':0, 'b':1, 'c':2}
cd: r({'a':0, 'b':1, 'c':2, 'd':3}).lt({'a':0, 'b':1, 'c':2})
ot: false
- py: r.expr({'a':0, 'b':1, 'c':2}) < {'a':0, 'b':1, 'c':2, 'd':3}
cd: r({'a':0, 'b':1, 'c':2}).lt({'a':0, 'b':1, 'c':2, 'd':3})
ot: true
- py: r.expr({'a':0, 'c':2}) < {'a':0, 'b':1, 'c':2}
cd: r({'a':0, 'c':2}).lt({'a':0, 'b':1, 'c':2})
ot: false
- py: r.expr({'a':0, 'c':2}) > {'a':0, 'b':1, 'c':2}
cd: r({'a':0, 'c':2}).gt({'a':0, 'b':1, 'c':2})
ot: true
# Comparisons across types
# RQL primitive types compare as if mapped to the following numbers
# MINVAL: 0
# ARRAY: 1
# BINARY: 2
# BOOLEAN: 3
# NULL: 4
# NUMBER: 5
# OBJECT: 6
# STRING: 7
# MAXVAL: 8
- def:
py: everything = r.expr([[],r.now(),r.binary(b"\x00"),false,null,-5,{},"a",r.maxval])
js: everything = r.expr([[],r.now(),r.binary(Buffer("\x00")),false,null,-5,{},"a",r.maxval])
rb: everything = r.expr([[],r.now(),r.binary("\x00"),false,null,-5,{},"a",r.maxval])
- js: r.and(r.args(everything.map(r.lt(r.minval, r.row))))
py: r.and_(r.args(everything.map(r.lt(r.minval, r.row))))
rb: r.and(r.args(everything.map{|x| r.lt(r.minval, x)}))
ot: true
- js: r.or(r.args(everything.map(r.gt(r.minval, r.row))))
py: r.or_(r.args(everything.map(r.gt(r.minval, r.row))))
rb: r.or(r.args(everything.map{|x| r.gt(r.minval, x)}))
ot: false
- cd: r.eq(r.minval, r.minval)
ot: true
- py: r.expr([]) < True
js: r([]).lt(true)
rb: r([]) < true
ot: true
- py: r.expr([1,2]) < False
js: r([1,2]).lt(false)
rb: r([1,2]) < false
ot: true
- py: r.expr(False) < []
js: r(false).lt([])
rb: r(false) < []
ot: false
- py: r.expr([]) < r.binary(b"\xAE")
js: r([]).lt(r.binary(Buffer("\x00")))
rb: r([]) < r.binary("")
ot: true
- py: r.expr([1,2]) < r.binary(b"\xAE")
js: r([1,2]).lt(r.binary(Buffer("\x00")))
rb: r([1,2]) < r.binary("")
ot: true
- py: True < r.expr(null)
js: r(true).lt(null)
rb: r(true) < null
ot: true
- py: r.expr(null) > []
js: r(null).gt([])
rb: r(null) > []
ot: true
- py: r.expr(null) < 12
js: r(null).lt(12)
rb: r(null) < 12
ot: true
- py: r.expr(null) < -2
js: r(null).lt(-2)
rb: r(null) < -2
ot: true
- py: r.expr(-12) < {}
js: r(-12).lt({})
rb: r(-12) < {}
ot: true
- py: r.expr(100) < {'a':-12}
js: r(100).lt({a:-12})
rb: r(100) < { :a => 12 }
ot: true
- py: r.expr(r.binary(b"\xAE")) < 12
js: r(r.binary(Buffer("\x00"))).lt(12)
rb: r(r.binary("")) < 12
ot: false
- py: r.binary(b"0xAE") < 'abc'
js: r.binary(Buffer("0x00")).lt('abc')
rb: r.binary("") < 'abc'
ot: true
- py: r.binary(b"0xAE") > r.now()
js: r.binary(Buffer("0x00")).gt(r.now())
rb: r.binary("") > r.now()
ot: false
- cd: r.now() > 12
js: r.now().gt(12)
ot: true
- cd: r.now() > 'abc'
js: r.now().gt('abc')
ot: false
- py: r.expr("abc") > {'a':-12}
js: r('abc').gt({a:-12})
rb: r('abc') > { :a => 12 }
ot: true
- py: r.expr("abc") > {'abc':'abc'}
js: r('abc').gt({abc:'abc'})
rb: r('abc') > { :abc => 'abc' }
ot: true
- py: r.expr('zzz') > 128
js: r('zzz').gt(128)
rb: r('zzz') > 128
ot: true
- py: r.expr('zzz') > {}
js: r('zzz').gt({})
rb: r('zzz') > {}
ot: true
- py: 'zzz' > r.expr(-152)
js: r('zzz').gt(-152)
rb: r('zzz') > -152
ot: true
- py: 'zzz' > r.expr(null)
js: r('zzz').gt(null)
rb: r('zzz') > null
ot: true
- py: 'zzz' > r.expr([])
js: r('zzz').gt([])
rb: r('zzz') > []
ot: true
- def:
rb: everything2 = r.expr([r.minval,[],r.now(),r.binary("\x00"),false,null,-5,{},"a"])
py: everything2 = r.expr([r.minval,[],r.now(),r.binary(b"\x00"),false,null,-5,{},"a"])
js: everything2 = r.expr([r.minval,[],r.now(),r.binary(Buffer("\x00")),false,null,-5,{},"a"])
- js: r.and(r.args(everything2.map(r.gt(r.maxval, r.row))))
py: r.and_(r.args(everything2.map(r.gt(r.maxval, r.row))))
rb: r.and(r.args(everything2.map{|x| r.gt(r.maxval, x)}))
ot: true
- js: r.or(r.args(everything2.map(r.lt(r.maxval, r.row))))
py: r.or_(r.args(everything2.map(r.lt(r.maxval, r.row))))
rb: r.or(r.args(everything2.map{|x| r.lt(r.maxval, x)}))
ot: false
- cd: r.eq(r.maxval, r.maxval)
ot: true