Sha256: e62379e1d9e7659a93b88a306b3829275affd818ba8ecb96590b3898fa01a2bb

Contents?: true

Size: 1.73 KB

Versions: 32

Compression:

Stored size: 1.73 KB

Contents

require "spec"
require "../src/*"

describe "Binary" do
  it "binary 0 is decimal 0" do
    Binary.to_decimal("0").should eq(0)
  end

  pending "binary 1 is decimal 1" do
    Binary.to_decimal("1").should eq(1)
  end

  pending "binary 10 is decimal 2" do
    Binary.to_decimal("10").should eq(2)
  end

  pending "binary 11 is decimal 3" do
    Binary.to_decimal("11").should eq(3)
  end

  pending "binary 100 is decimal 4" do
    Binary.to_decimal("100").should eq(4)
  end

  pending "binary 1001 is decimal 9" do
    Binary.to_decimal("1001").should eq(9)
  end

  pending "binary 11010 is decimal 26" do
    Binary.to_decimal("11010").should eq(26)
  end

  pending "binary 10001101000 is decimal 1128" do
    Binary.to_decimal("10001101000").should eq(1128)
  end

  pending "binary ignores leading zeros" do
    Binary.to_decimal("000011111").should eq(31)
  end

  pending "2 is not a valid binary digit" do
    expect_raises(ArgumentError) do
      Binary.to_decimal("2")
    end
  end

  pending "a number containing a non-binary digit is invalid" do
    expect_raises(ArgumentError) do
      Binary.to_decimal("01201")
    end
  end

  pending "a number with trailing non-binary characters is invalid" do
    expect_raises(ArgumentError) do
      Binary.to_decimal("10nope")
    end
  end

  pending "a number with leading non-binary characters is invalid" do
    expect_raises(ArgumentError) do
      Binary.to_decimal("nope10")
    end
  end

  pending "a number with internal non-binary characters is invalid" do
    expect_raises(ArgumentError) do
      Binary.to_decimal("10nope10")
    end
  end

  pending "a number and a word whitespace separated is invalid" do
    expect_raises(ArgumentError) do
      Binary.to_decimal("001 nope")
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/crystal/exercises/binary/spec/binary_spec.cr
trackler-2.2.1.179 tracks/crystal/exercises/binary/spec/binary_spec.cr
trackler-2.2.1.178 tracks/crystal/exercises/binary/spec/binary_spec.cr
trackler-2.2.1.177 tracks/crystal/exercises/binary/spec/binary_spec.cr
trackler-2.2.1.176 tracks/crystal/exercises/binary/spec/binary_spec.cr
trackler-2.2.1.175 tracks/crystal/exercises/binary/spec/binary_spec.cr
trackler-2.2.1.174 tracks/crystal/exercises/binary/spec/binary_spec.cr
trackler-2.2.1.173 tracks/crystal/exercises/binary/spec/binary_spec.cr
trackler-2.2.1.172 tracks/crystal/exercises/binary/spec/binary_spec.cr
trackler-2.2.1.171 tracks/crystal/exercises/binary/spec/binary_spec.cr
trackler-2.2.1.170 tracks/crystal/exercises/binary/spec/binary_spec.cr
trackler-2.2.1.169 tracks/crystal/exercises/binary/spec/binary_spec.cr
trackler-2.2.1.167 tracks/crystal/exercises/binary/spec/binary_spec.cr
trackler-2.2.1.166 tracks/crystal/exercises/binary/spec/binary_spec.cr
trackler-2.2.1.165 tracks/crystal/exercises/binary/spec/binary_spec.cr
trackler-2.2.1.164 tracks/crystal/exercises/binary/spec/binary_spec.cr
trackler-2.2.1.163 tracks/crystal/exercises/binary/spec/binary_spec.cr
trackler-2.2.1.162 tracks/crystal/exercises/binary/spec/binary_spec.cr
trackler-2.2.1.161 tracks/crystal/exercises/binary/spec/binary_spec.cr
trackler-2.2.1.160 tracks/crystal/exercises/binary/spec/binary_spec.cr