Created
January 18, 2012 13:03
-
-
Save porras/1632918 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
| require 'mrproper' | |
| # assuming Croupier.normal(i, m = 0, v = 1) returns an array of i elements following a normal distribution with mean m and variance v | |
| properties 'normal(i, m, v)' do | |
| data :i => 1..9999, | |
| :m => -10.0..10.0, | |
| :v => 0.0..10.0 | |
| property 'has i elements' do |data| | |
| assert_equal data[:i], Croupier.normal(data[:i], data[:m], data[:v]).size | |
| end | |
| property 'is distributed like a normal distribution' do |data| | |
| assert_normal Croupier.normal(data[:i], data[:m], data[:v]) | |
| end | |
| property 'has mean m' do |data| | |
| assert_equal data[:m], mean(Croupier.normal(data[:i], data[:m], data[:v])) | |
| # actually you shouldn't test they're equal but “close” | |
| end | |
| property 'has variance v' do |data| | |
| assert_equal data[:v], variance(Croupier.normal(data[:i], data[:m], data[:v])) | |
| # actually you shouldn't test they're equal but “close” | |
| end | |
| end | |
| properties 'normal(i)' do | |
| data 1..9999 | |
| property 'has mean 0' do |data| | |
| assert_equal 0.0, mean(Croupier.normal(data[:i], data[:m], data[:v])) | |
| # actually you shouldn't test they're equal but “close” | |
| end | |
| property 'has variance 1' do |data| | |
| assert_equal 1.0, variance(Croupier.normal(data[:i], data[:m], data[:v])) | |
| # actually you shouldn't test they're equal but “close” | |
| end | |
| end | |
| def assert_normal(sample) | |
| # come on guys, you're supposed to know math! | |
| end | |
| def mean(sample) | |
| # come on guys, you're supposed to know math! | |
| end | |
| def variance(sample) | |
| # come on guys, you're supposed to know math! | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment