Last active
October 31, 2017 12:08
-
-
Save bChiquet/e7d8ce4c26c90d951f27356198a9acf6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe "Insurance Bonus system" $ do | |
describe "evolution without accident" $ do | |
it "starts at 100 for new drivers" $ | |
bonus new `shouldBe` 100 | |
it "after each year without accident, it decreases by 5%" $ do | |
bonus (new >- Year) `shouldBe` 95 | |
bonus (new >- Year >- Year) `shouldBe` 90 | |
bonus (years 5) `shouldBe` 76 | |
it "never goes under 50%" $ do | |
bonus (caped) `shouldBe` 50 | |
bonus (caped >- Year) `shouldBe` 50 | |
describe "accident effect on bonus" $ do | |
it "Liable accidents increase bonus by 25%" $ do | |
bonus (new >- (Accident Liable)) `shouldBe` 125 | |
bonus ((years 6) >- (Accident Liable)) `shouldBe` 90 | |
it "Split accidents increase bonus by 12.5%" $ do | |
bonus (new >- (Accident Split)) `shouldBe` 112 | |
bonus ((years 6) >- (Accident Split)) `shouldBe` 81 | |
it "No bonus is acquired the year of an accident" $ do | |
bonus (new >- (Accident Liable) >- Year) `shouldBe` 125 | |
bonus ((years 6) >- (Accident Split) >- Year) `shouldBe` 81 | |
it "bonus never goes above 350%" $ do | |
bonus wrecked `shouldBe` 350 | |
bonus (wrecked >- (Accident Liable)) `shouldBe` 350 | |
describe "special rules" $ do | |
it "after two years without accidents, coef is reduced to 100 if above" $ do | |
bonus (wrecked >- Year >- Year) `shouldBe` 100 | |
bonus (wrecked >- Year >- Year >- Year) `shouldBe` 95 | |
it "if coef has been at 50 for 3 years next accident is ignored" $ do | |
bonus (caped >- Year >- Year >- Year >- (Accident Liable)) `shouldBe` 50 | |
wrecked = foldl (>-) new (replicate 20 (Accident Liable)) | |
years n = foldl (>-) new (replicate n Year) | |
caped = years 13 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment