Sha256: 10f882e3e230e284be2e7681fb8e44b4570d43bf8da1b43fbe8fdd5818d8c4fd

Contents?: true

Size: 1.09 KB

Versions: 55

Compression:

Stored size: 1.09 KB

Contents

require 'test_helper'
require 'tins'

module Tins
  class TokenTest < Test::Unit::TestCase
    def test_token_failures
      assert_raise(ArgumentError) { Tins::Token.new(bits: 0) }
      assert_raise(ArgumentError) { Tins::Token.new(length: 0) }
      assert_raise(ArgumentError) { Tins::Token.new(alphabet: %w[0]) }
    end

    def test_token_for_length
      token = Tins::Token.new(length: 22)
      assert_equal 22, token.length
      assert_equal 130, token.bits
    end

    def test_token_for_bits
      token = Tins::Token.new(bits: 128)
      assert_equal 22, token.length
      # can differ from bits argument depending on alphabet:
      assert_equal 130, token.bits
    end

    def test_alphabet
      token = Tins::Token.new(alphabet: %w[0 1])
      assert_equal 128, token.length
      assert_equal 128, token.bits
      token = Tins::Token.new(alphabet: %w[0 1 2 3])
      assert_equal 64, token.length
      assert_equal 128, token.bits
      token = Tins::Token.new(length: 128, alphabet: %w[0 1 2 3])
      assert_equal 128, token.length
      assert_equal 256, token.bits
    end
  end
end

Version data entries

55 entries across 45 versions & 2 rubygems

Version Path
tins-1.34.0 tests/token_test.rb
tins-1.33.0 tests/token_test.rb
tdiary-5.2.4 vendor/bundle/ruby/3.1.0/gems/tins-1.31.1/tests/token_test.rb
tins-1.32.1 tests/token_test.rb
tins-1.32.0 tests/token_test.rb
tdiary-5.2.3 vendor/bundle/ruby/3.1.0/gems/tins-1.31.1/tests/token_test.rb
tdiary-5.2.2 vendor/bundle/ruby/3.1.0/gems/tins-1.31.1/tests/token_test.rb
tins-1.31.1 tests/token_test.rb
tdiary-5.2.1 vendor/bundle/ruby/3.1.0/gems/tins-1.31.0/tests/token_test.rb
tins-1.31.0 tests/token_test.rb
tins-1.30.0 tests/token_test.rb
tdiary-5.2.0 vendor/bundle/ruby/2.7.0/gems/tins-1.29.1/tests/token_test.rb
tdiary-5.2.0 vendor/bundle/ruby/3.0.0/gems/tins-1.29.1/tests/token_test.rb
tdiary-5.1.7 vendor/bundle/ruby/2.7.0/gems/tins-1.29.1/tests/token_test.rb
tdiary-5.1.7 vendor/bundle/ruby/3.0.0/gems/tins-1.29.1/tests/token_test.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/2.7.0/gems/tins-1.28.0/tests/token_test.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/tins-1.26.0/tests/token_test.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tins-1.29.1/tests/token_test.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/tdiary-5.1.4/vendor/bundle/ruby/2.7.0/gems/tins-1.26.0/tests/token_test.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tins-1.28.0/tests/token_test.rb