summaryrefslogtreecommitdiff
path: root/test/unit/zbase_test.rb
blob: e2997a3074969ce2ff54120d9b0033ab4d567178 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
require 'minitest/autorun'
require 'zbase32'

class Zbase32Test < Minitest::Test
  def test_samples
    samples.each do |k, v|
      assert_equal k, decode(v)
      assert_equal v, encode(k)
    end
  end

  protected

  def samples
    {
      '111100001011111111000111' => '6n9hq',
      '110101000111101000000100' => '4t7ye',
      wkd_sample => 'iy9q119eutrkn8s1mk4r39qejnbu3n5q'
    }
  end

  def wkd_sample
    'a83ee94be89c48a11ed25ab44cfdc848833c8b6e'.to_i(16).to_s(2)
  end

  def encode(string)
    ZBase32.encode32 string
  end

  def decode(enc)
    ZBase32.decode32 enc
  end
end