|
@@ -0,0 +1,41 @@
|
|
1
|
+module Chervil
|
|
2
|
+ RSpec.describe Core do
|
|
3
|
+ it 'does arithmetic' do
|
|
4
|
+ expect(Core::CORE['+'].call([1.0, 2.0])).to eq(3.0)
|
|
5
|
+ expect(Core::CORE['-'].call([3.0, 1.0])).to eq(2.0)
|
|
6
|
+ expect(Core::CORE['*'].call([2.0, 3.0])).to eq(6.0)
|
|
7
|
+ expect(Core::CORE['/'].call([6.0, 2.0])).to eq(3.0)
|
|
8
|
+ end
|
|
9
|
+
|
|
10
|
+ it 'compares values' do
|
|
11
|
+ expect(Core::CORE['='].call([1.0, 2.0])).to eq(false)
|
|
12
|
+ expect(Core::CORE['='].call([1.0, 1.0])).to eq(true)
|
|
13
|
+ expect(Core::CORE['<'].call([2.0, 1.0])).to eq(false)
|
|
14
|
+ expect(Core::CORE['<'].call([2.0, 3.0])).to eq(true)
|
|
15
|
+ expect(Core::CORE['>'].call([2.0, 1.0])).to eq(true)
|
|
16
|
+ expect(Core::CORE['>'].call([2.0, 3.0])).to eq(false)
|
|
17
|
+ expect(Core::CORE['<='].call([2.0, 1.0])).to eq(false)
|
|
18
|
+ expect(Core::CORE['<='].call([2.0, 2.0])).to eq(true)
|
|
19
|
+ expect(Core::CORE['>='].call([2.0, 2.0])).to eq(true)
|
|
20
|
+ expect(Core::CORE['>='].call([2.0, 3.0])).to eq(false)
|
|
21
|
+ expect(Core::CORE['and'].call([2.0, 3.0])).to eq(true)
|
|
22
|
+ expect(Core::CORE['and'].call([2.0, 3.0, false])).to eq(false)
|
|
23
|
+ expect(Core::CORE['or'].call([2.0, 3.0, false])).to eq(true)
|
|
24
|
+ expect(Core::CORE['or'].call([false, false])).to eq(false)
|
|
25
|
+ expect(Core::CORE['not'].call([1.0])).to eq(false)
|
|
26
|
+ expect(Core::CORE['not'].call([false])).to eq(true)
|
|
27
|
+ end
|
|
28
|
+
|
|
29
|
+ it 'returns an error if argument has the wrong type' do
|
|
30
|
+ expect(Core::CORE['+'].call([1.0, "hello"])).to eq(
|
|
31
|
+ Error.new("Expected an argument of type number but got string")
|
|
32
|
+ )
|
|
33
|
+ end
|
|
34
|
+
|
|
35
|
+ it 'returns an error if given the wrong number of arguments' do
|
|
36
|
+ expect(Core::CORE['not'].call([1.0, 2.0])).to eq(
|
|
37
|
+ Error.new("Expected 1 argument but received 2")
|
|
38
|
+ )
|
|
39
|
+ end
|
|
40
|
+ end
|
|
41
|
+end
|