|
9 | 9 | end |
10 | 10 | end |
11 | 11 |
|
| 12 | + describe "is_constant?" do |
| 13 | + it "is true" do |
| 14 | + expect(described_class.new(true).is_constant?).to eq true |
| 15 | + end |
| 16 | + end |
| 17 | + |
12 | 18 | describe "operations" do |
13 | 19 | it "should reduce to the answer right away" do |
14 | 20 | res = !Keisan::AST::Boolean.new(true) |
|
41 | 47 | expect(negative_or).to be_a(Keisan::AST::Boolean) |
42 | 48 | expect(negative_or.value).to eq false |
43 | 49 |
|
44 | | - and_other = described_class.new(true).and Keisan::AST::Number.new(1) |
45 | | - or_other = described_class.new(true).or Keisan::AST::Number.new(1) |
| 50 | + and_other = described_class.new(true).and Keisan::AST::Variable.new("x") |
| 51 | + or_other = described_class.new(true).or Keisan::AST::Variable.new("x") |
46 | 52 |
|
47 | 53 | expect(and_other).to be_a(Keisan::AST::LogicalAnd) |
48 | 54 | expect(or_other).to be_a(Keisan::AST::LogicalOr) |
| 55 | + |
| 56 | + expect{described_class.new(true).and Keisan::AST::Number.new(1)}.to raise_error(Keisan::Exceptions::InvalidExpression) |
| 57 | + expect{described_class.new(true).or Keisan::AST::Number.new(1)}.to raise_error(Keisan::Exceptions::InvalidExpression) |
49 | 58 | end |
50 | 59 |
|
51 | 60 | it "can do == and != checks" do |
|
63 | 72 | expect(negative_not_equal).to be_a(Keisan::AST::Boolean) |
64 | 73 | expect(negative_not_equal.value).to eq false |
65 | 74 |
|
66 | | - equal_other = described_class.new(true).equal Keisan::AST::Number.new(1) |
67 | | - not_equal_other = described_class.new(true).not_equal Keisan::AST::Number.new(1) |
| 75 | + equal_other = described_class.new(true).equal Keisan::AST::Variable.new("x") |
| 76 | + not_equal_other = described_class.new(true).not_equal Keisan::AST::Variable.new("x") |
68 | 77 |
|
69 | 78 | expect(equal_other).to be_a(Keisan::AST::LogicalEqual) |
70 | 79 | expect(not_equal_other).to be_a(Keisan::AST::LogicalNotEqual) |
| 80 | + |
| 81 | + equal_number = described_class.new(true).equal Keisan::AST::Number.new(1) |
| 82 | + expect(equal_number).to be_a(Keisan::AST::Boolean) |
| 83 | + expect(equal_number.value).to eq false |
| 84 | + not_equal_number = described_class.new(true).not_equal Keisan::AST::Number.new(1) |
| 85 | + expect(not_equal_number).to be_a(Keisan::AST::Boolean) |
| 86 | + expect(not_equal_number.value).to eq true |
71 | 87 | end |
72 | 88 | end |
73 | 89 | end |
0 commit comments