-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommonFunctions_spec.rb
63 lines (46 loc) · 2.1 KB
/
commonFunctions_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
require 'dotenv/load'
require 'mongo'
require './commonFunctions.rb'
Mongo::Logger.logger.level = Logger::FATAL
mongo = Mongo::Client.new([ ENV['MONGO_URL'] ], :database => ENV['MONGO_DB'])
RSpec.describe "commonFunctions" do
it "adds commas" do
expect(number_with_commas(1000)).to eq("1,000")
expect(number_with_commas(1000.00)).to eq("1,000.0")
end
it "grows population" do
expect(getNewPopulation(100, 0.5, 0.5, 0)).to eq(100)
expect(getNewPopulation(100, 1.0, 0.5, 0)).to be > (100)
expect(getNewPopulation(100, 0.0, 0.5, 0)).to be < (100)
expect(getNewPopulation(100, 0.5, 1.0, 0)).to be > (100)
expect(getNewPopulation(100, 0.5, 0.0, 0)).to eq(100)
end
it "gets new happiness" do
# test tax
expect(getNewHappiness(0.5, 0.325, nil, 1.0)).to be_between(0.499, 0.501)
expect(getNewHappiness(0.5, 0.4, nil, 1.0)).to be < 0.5
expect(getNewHappiness(0.5, 0.2, nil, 1.0)).to be > 0.5
# test last lost battle
expect(getNewHappiness(0.5, 0.325, Time.now, 1.0)).to be < 0.4751
expect(getNewHappiness(0.5, 0.325, Time.now - 60 * 60 * 4, 1.0)).to be_between(0.499, 0.501)
#test reputation
expect(getNewHappiness(0.5, 0.325, nil, 1.0)).to be_between(0.499, 0.501)
expect(getNewHappiness(0.5, 0.325, nil, 0.5)).to be < 0.5
expect(getNewHappiness(0.5, 0.325, nil, 0.0)).to eq 0.45
end
it "slopeInterpolate works for tax rage" do
expect(slopeInterpolate(0.325, 0.0, 1.0, 0.0, 1.0, 0.9)).to be_between(0.499, 0.501)
expect(slopeInterpolate(0.0, 0.0, 1.0, 0.0, 1.0, 0.9)).to eq(0.0)
expect(slopeInterpolate(1.0, 0.0, 1.0, 0.0, 1.0, 0.9)).to eq(1.0)
end
it "gets new reputation" do
expect( getReputationFromAttack(1000, 1000, 1.0) ).to eq(1.0)
expect( getReputationFromAttack(1000, 1000, 0.5) ).to eq(0.5)
expect( getReputationFromAttack(1000, 0, 1.0) ).to eq(0.0)
end
it "gets new rep" do
expect( getNewReputation(0.5, Time.now) ).to be > 0.5
end
it "adjusts market" do
end
end