1234567891011121314151617181920212223242526272829303132333435363738394041 |
- module Chervil
- RSpec.describe Core do
- it 'does arithmetic' do
- expect(Core::CORE['+'].call([1.0, 2.0])).to eq(3.0)
- expect(Core::CORE['-'].call([3.0, 1.0])).to eq(2.0)
- expect(Core::CORE['*'].call([2.0, 3.0])).to eq(6.0)
- expect(Core::CORE['/'].call([6.0, 2.0])).to eq(3.0)
- end
-
- it 'compares values' do
- expect(Core::CORE['='].call([1.0, 2.0])).to eq(false)
- expect(Core::CORE['='].call([1.0, 1.0])).to eq(true)
- expect(Core::CORE['<'].call([2.0, 1.0])).to eq(false)
- expect(Core::CORE['<'].call([2.0, 3.0])).to eq(true)
- expect(Core::CORE['>'].call([2.0, 1.0])).to eq(true)
- expect(Core::CORE['>'].call([2.0, 3.0])).to eq(false)
- expect(Core::CORE['<='].call([2.0, 1.0])).to eq(false)
- expect(Core::CORE['<='].call([2.0, 2.0])).to eq(true)
- expect(Core::CORE['>='].call([2.0, 2.0])).to eq(true)
- expect(Core::CORE['>='].call([2.0, 3.0])).to eq(false)
- expect(Core::CORE['and'].call([2.0, 3.0])).to eq(true)
- expect(Core::CORE['and'].call([2.0, 3.0, false])).to eq(false)
- expect(Core::CORE['or'].call([2.0, 3.0, false])).to eq(true)
- expect(Core::CORE['or'].call([false, false])).to eq(false)
- expect(Core::CORE['not'].call([1.0])).to eq(false)
- expect(Core::CORE['not'].call([false])).to eq(true)
- end
-
- it 'returns an error if argument has the wrong type' do
- expect(Core::CORE['+'].call([1.0, "hello"])).to eq(
- Error.new("Expected an argument of type number but got string")
- )
- end
-
- it 'returns an error if given the wrong number of arguments' do
- expect(Core::CORE['not'].call([1.0, 2.0])).to eq(
- Error.new("Expected 1 argument but received 2")
- )
- end
- end
- end
|