Skip to content

Commit

Permalink
Merge pull request #55 from kachick/add-test-cases-to-refer-rafaelsales
Browse files Browse the repository at this point in the history
Add tests for some example values from `rafaelsales/ulid`
  • Loading branch information
kachick authored May 1, 2021
2 parents 3b339d5 + b55c438 commit 1e615b6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
11 changes: 0 additions & 11 deletions test/test_ulid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,17 +192,6 @@ def test_generate
assert_equal(entropy, ULID.generate(entropy: entropy).entropy)
end

def test_milliseconds_precision_order
# The test cases taken from https://github.com/rafaelsales/ulid/pull/23
ulids = 1000.times.map do |milliseconds|
time = Time.new(2020, 1, 2, 3, 4, Rational(milliseconds, 10 ** 3))

ULID.generate(moment: time)
end

assert_equal(ulids, ulids.sort)
end

def test_from_uuidv4
# The example value was taken from https://github.com/ahawker/ulid/tree/96bdb1daad7ce96f6db8c91ac0410b66d2e1c4c1#usage
assert_equal(ULID.parse('09GF8A5ZRN9P1RYDVXV52VBAHS'), ULID.from_uuidv4('0983d0a2-ff15-4d83-8f37-7dd945b5aa39'))
Expand Down
14 changes: 14 additions & 0 deletions test/test_ulid_example_values.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,18 @@ def test_oklog_examples
# https://github.com/oklog/ulid/blob/e7ac4de44d238ff4707cc84b9c98ae471f31e2d1/ulid_test.go#L690-L712
assert_instance_of(ULID, ULID.parse('0000XSNJG0MQJHBF4QX1EFD6Y3'))
end

def test_rafaelsales_examples
# https://github.com/rafaelsales/ulid/blob/0eafbe3394539d12ad471f01e935b949f85c7093/spec/lib/ulid_spec.rb#L39-L40
time = Time.at(1_469_918_176, 385, :millisecond)
assert_equal('01ARYZ6S41', ULID.generate(moment: time).timestamp)

# https://github.com/rafaelsales/ulid/pull/23
ulids = 1000.times.map do |milliseconds|
time = Time.new(2020, 1, 2, 3, 4, Rational(milliseconds, 10 ** 3))

ULID.generate(moment: time)
end
assert_equal(ulids, ulids.sort)
end
end

0 comments on commit 1e615b6

Please sign in to comment.