diff --git a/lib/pycall/pytypeobject_wrapper.rb b/lib/pycall/pytypeobject_wrapper.rb index 5f7958c1..46dc25bd 100644 --- a/lib/pycall/pytypeobject_wrapper.rb +++ b/lib/pycall/pytypeobject_wrapper.rb @@ -78,6 +78,26 @@ def <=>(other) nil end + def <(other) + cmp = self <=> other + cmp && cmp < 0 + end + + def >(other) + cmp = self <=> other + cmp && cmp > 0 + end + + def <=(other) + cmp = self <=> other + cmp && cmp <= 0 + end + + def >=(other) + cmp = self <=> other + cmp && cmp >= 0 + end + private def register_python_type_mapping diff --git a/spec/pycall/pytypeobject_wrapper_spec.rb b/spec/pycall/pytypeobject_wrapper_spec.rb index 9c5e35c1..5ea80aeb 100644 --- a/spec/pycall/pytypeobject_wrapper_spec.rb +++ b/spec/pycall/pytypeobject_wrapper_spec.rb @@ -114,6 +114,58 @@ module PyCall end end + describe '#<' do + specify do + expect(PyCall.builtins.list < PyCall.builtins.list).to eq(false) + expect(PyCall.builtins.list < PyCall.builtins.object).to eq(true) + expect(PyCall.builtins.object < PyCall.builtins.list).to eq(false) + expect(PyCall.builtins.list < PyCall.builtins.dict).to eq(nil) + expect(PyCall.builtins.list < Object).to eq(true) + expect(PyCall.builtins.list < Array).to eq(nil) + expect(PyCall.builtins.list < Conversion.from_ruby(42)).to eq(nil) + expect(PyCall.builtins.list < 42).to eq(nil) + end + end + + describe '#>' do + specify do + expect(PyCall.builtins.list > PyCall.builtins.list).to eq(false) + expect(PyCall.builtins.list > PyCall.builtins.object).to eq(false) + expect(PyCall.builtins.object > PyCall.builtins.list).to eq(true) + expect(PyCall.builtins.list > PyCall.builtins.dict).to eq(nil) + expect(PyCall.builtins.list > Object).to eq(false) + expect(PyCall.builtins.list > Array).to eq(nil) + expect(PyCall.builtins.list > Conversion.from_ruby(42)).to eq(nil) + expect(PyCall.builtins.list > 42).to eq(nil) + end + end + + describe '#<=' do + specify do + expect(PyCall.builtins.list <= PyCall.builtins.list).to eq(true) + expect(PyCall.builtins.list <= PyCall.builtins.object).to eq(true) + expect(PyCall.builtins.object <= PyCall.builtins.list).to eq(false) + expect(PyCall.builtins.list <= PyCall.builtins.dict).to eq(nil) + expect(PyCall.builtins.list <= Object).to eq(true) + expect(PyCall.builtins.list <= Array).to eq(nil) + expect(PyCall.builtins.list <= Conversion.from_ruby(42)).to eq(nil) + expect(PyCall.builtins.list <= 42).to eq(nil) + end + end + + describe '#>=' do + specify do + expect(PyCall.builtins.list >= PyCall.builtins.list).to eq(true) + expect(PyCall.builtins.list >= PyCall.builtins.object).to eq(false) + expect(PyCall.builtins.object >= PyCall.builtins.list).to eq(true) + expect(PyCall.builtins.list >= PyCall.builtins.dict).to eq(nil) + expect(PyCall.builtins.list >= Object).to eq(false) + expect(PyCall.builtins.list >= Array).to eq(nil) + expect(PyCall.builtins.list >= Conversion.from_ruby(42)).to eq(nil) + expect(PyCall.builtins.list >= 42).to eq(nil) + end + end + describe '#===' do specify do expect(PyCall.builtins.tuple === PyCall.tuple()).to eq(true)