exalted_math 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
data/exalted_math.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{exalted_math}
8
- s.version = "0.1.1"
8
+ s.version = "0.1.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jonathan Stott"]
@@ -28,7 +28,7 @@ module Exalted
28
28
  true
29
29
  when 'stat', 'spec'
30
30
  false
31
- when 'max'
31
+ when 'max', 'min'
32
32
  self[2].all? { |ast| ast.constant? }
33
33
  else
34
34
  raise UnknownNodeError, self[0]
data/spec/ast_spec.rb CHANGED
@@ -22,6 +22,8 @@ describe "Exalted::Ast" do
22
22
  @mul_foo = Exalted::Ast.new('mul', @three, @foo)
23
23
  @div_foo = Exalted::Ast.new('div', @three, @foo)
24
24
  @nested = Exalted::Ast.new('mul', @add, @sub_foo)
25
+ @min = Exalted::Ast.new('min', 1, [@three, @seven] )
26
+ @max = Exalted::Ast.new('max', 1, [@three, @seven] )
25
27
  @context = { 'foo' => 3, 'bar' => 4 }
26
28
  end
27
29
 
@@ -53,6 +55,14 @@ describe "Exalted::Ast" do
53
55
  @div.should == Ast.div(@seven, @three)
54
56
  end
55
57
 
58
+ it ".min makes a min" do
59
+ @min.should == Ast.min(1, [@three, @seven])
60
+ end
61
+
62
+ it ".max makes a max" do
63
+ @max.should == Ast.max(1, [@three, @seven])
64
+ end
65
+
56
66
  it "a number is constant" do
57
67
  @three.should.be.constant
58
68
  end
@@ -73,6 +83,12 @@ describe "Exalted::Ast" do
73
83
  it "an div of two constants is constant" do
74
84
  @div.should.be.constant
75
85
  end
86
+ it "a min of constants is constant" do
87
+ @min.should.be.constant
88
+ end
89
+ it "a max of constants is constant" do
90
+ @max.should.be.constant
91
+ end
76
92
 
77
93
  it "an add of constant and not constant is not constant" do
78
94
  @add_foo.should.not.be.constant
@@ -154,6 +170,13 @@ describe "Exalted::Ast" do
154
170
  Exalted::Ast.value(@div, @context).should == 2
155
171
  end
156
172
 
173
+ it "the value of a min is the mininum value" do
174
+ Exalted::Ast.value(@min, @context).should == 3
175
+ end
176
+ it "the value of a max is the maxinum value" do
177
+ Exalted::Ast.value(@max, @context).should == 7
178
+ end
179
+
157
180
  it "it walks the whole tree to compute a value" do
158
181
  Exalted::Ast.value(@nested, @context).should == 0
159
182
  end
data/spec/parser_spec.rb CHANGED
@@ -17,7 +17,9 @@ describe "Exalted::MathParser" do
17
17
  ['3 + 4', Ast.add(Ast.num(3), Ast.num(4) )],
18
18
  ['6 / 3', Ast.div(Ast.num(6), Ast.num(3) )],
19
19
  ['Essence * 4', Ast.mul(Ast.stat('essence'), Ast.num(4) )],
20
- ['(Essence * 4) + Willpower', Ast.add(Ast.mul(Ast.stat('essence'), Ast.num(4) ), Ast.stat('willpower'))]
20
+ ['(Essence * 4) + Willpower', Ast.add(Ast.mul(Ast.stat('essence'), Ast.num(4) ), Ast.stat('willpower'))],
21
+ ['highest[2](compassion,conviction,temperance,valor)', Ast.max(2, [Ast.stat('compassion'),Ast.stat('conviction'),Ast.stat('temperance'),Ast.stat('valor') ])],
22
+ ['min(compassion,conviction,temperance,valor)', Ast.min(1, [Ast.stat('compassion'),Ast.stat('conviction'),Ast.stat('temperance'),Ast.stat('valor') ])]
21
23
  ].each do |string, ast|
22
24
  it "parses '#{string}'" do
23
25
  success, result = @parser.ast(string)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exalted_math
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 1
10
- version: 0.1.1
9
+ - 2
10
+ version: 0.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jonathan Stott