Class: EntropyTest

Inherits:
Test::Unit::TestCase
  • Object
show all
Includes:
MoreMath::Functions
Defined in:
tests/entropy_test.rb

Instance Method Summary collapse

Methods included from MoreMath::Functions

#beta, beta, #beta_regularized, beta_regularized, #cantor_pairing, cantor_pairing, #cantor_pairing_inv, cantor_pairing_inv, #erf, #erfc, #gamma, gamma, #gammaP_regularized, gammaP_regularized, #gammaQ_regularized, gammaQ_regularized, #log_beta, log_beta, #log_ceil, log_ceil, #log_floor, log_floor, #log_gamma, #logb, logb, #numberify_string, numberify_string, #stringify_number, stringify_number

Instance Method Details

#setupObject



9
10
11
12
13
14
15
# File 'tests/entropy_test.rb', line 9

def setup
  @empty  = ''
  @low    = ?A * 42
  @string = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit'
  @high   = 'The quick brown fox jumps over the lazy dog'
  @random = "\xAC-\x8A\xF5\xA8\xF7\\\e\xB5\x8CI\x06\xA7"
end

#test_entropyObject



17
18
19
20
21
22
23
# File 'tests/entropy_test.rb', line 17

def test_entropy
  assert_equal 0, entropy(@empty)
  assert_equal 0, entropy(@low)
  assert_in_delta 3.9514, entropy(@string), 1E-3
  assert_in_delta 4.4319, entropy(@high), 1E-3
  assert_in_delta 3.700, entropy(@random), 1E-3
end

#test_entropy_idealObject



25
26
27
28
29
30
31
32
33
34
35
# File 'tests/entropy_test.rb', line 25

def test_entropy_ideal
  assert_equal 0, entropy_ideal(-1)
  assert_equal 0, entropy_ideal(0)
  assert_equal 0, entropy_ideal(0.5)
  assert_equal 0, entropy_ideal(1)
  assert_in_delta 1, entropy_ideal(2), 1E-3
  assert_in_delta 1.584, entropy_ideal(3), 1E-3
  assert_in_delta 3, entropy_ideal(8), 1E-3
  assert_in_delta 3.321, entropy_ideal(10), 1E-3
  assert_in_delta 4, entropy_ideal(16), 1E-3
end

#test_entropy_ratioObject



37
38
39
40
41
42
43
# File 'tests/entropy_test.rb', line 37

def test_entropy_ratio
  assert_equal 0, entropy_ratio(@empty)
  assert_equal 0, entropy_ratio(@low)
  assert_in_delta 0.6834, entropy_ratio(@string), 1E-3
  assert_in_delta 0.8167, entropy_ratio(@high), 1E-3
  assert_in_delta 1.0, entropy_ratio(@random), 1E-3
end