Sha256: 0859450b65aa8b5492c8bb91c7e3ce561ad77fa5b382169a0654ba65f076e5ea

Contents?: true

Size: 1.31 KB

Versions: 12

Compression:

Stored size: 1.31 KB

Contents

#!/usr/bin/env ruby

require 'test_helper'
require 'more_math'

class EntropyTest < Test::Unit::TestCase
  include MoreMath::Functions

  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

  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

  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

  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
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
more_math-1.3.0 tests/entropy_test.rb
more_math-1.2.2 tests/entropy_test.rb
more_math-1.2.1 tests/entropy_test.rb
more_math-1.2.0 tests/entropy_test.rb
more_math-1.1.0 tests/entropy_test.rb
more_math-1.0.2 tests/entropy_test.rb
more_math-1.0.1 tests/entropy_test.rb
more_math-1.0.0 tests/entropy_test.rb
more_math-0.4.0 tests/entropy_test.rb
more_math-0.3.3 tests/entropy_test.rb
more_math-0.3.2 tests/entropy_test.rb
more_math-0.3.1 tests/entropy_test.rb