Skip to content

Instantly share code, notes, and snippets.

@tmiller
Forked from anthonycrumley/range_test.rb
Created July 26, 2013 21:15
Show Gist options
  • Save tmiller/6092290 to your computer and use it in GitHub Desktop.
Save tmiller/6092290 to your computer and use it in GitHub Desktop.
require File.dirname(__FILE__) + '/../test_helper'
class RangeTest < Test::Unit::TestCase
test <<-TEST do
Range#coinsides_with?
|
|
TEST
range = Time.zone.now..Time.zone.now
assert (range).coinsides_with?(range)
end
test <<-TEST do
Range#coinsides_with?
|----|
|----|
TEST
range = 1.hour.ago..Time.zone.now
assert (range).coinsides_with?(range)
end
test "Range#coinsides_with?" do
message = <<-MESSAGE
This should coinside:
|
|
MESSAGE
range = Time.zone.now..Time.zone.now
refute (range).coinsides_with?(range), message
range = 1.hour.ago..Time.zone.now
refute (range).coinsides_with?(range), <<-MESSAGE
This should coinside:
|----|
|----|
MESSAGE
consistent_time = 1.hour.ago
foo = consistent_time..Time.zone.now
bar = consistent_time..1.hour.from_now
refute (foo).coinsides_with?(bar), <<-MESSAGE
This should coinside:
|----|
|--------|
MESSAGE
# |
# |
range = Time.zone.now..Time.zone.now
assert (range).coinsides_with?(range)
# |----|
# |----|
range = 1.hour.ago..Time.zone.now
assert (range).coinsides_with?(range)
# |----|
# |--------|
consistent_time = 1.hour.ago
assert (consistent_time..Time.zone.now).coinsides_with?(consistent_time..1.hour.from_now)
# |--------|
# |----|
consistent_time = 1.hour.ago
assert (consistent_time..1.hour.from_now).coinsides_with?(consistent_time..Time.zone.now)
# |----|
# |---------|
consistent_time = Time.zone.now
assert (1.hour.ago..consistent_time).coinsides_with?(2.hours.ago..consistent_time)
# |--------|
# |----|
consistent_time = Time.zone.now
assert (2.hours.ago..consistent_time).coinsides_with?(1.hour.ago..consistent_time)
# |----|
# |----|
consistent_time = Time.zone.now
assert (1.hour.ago..consistent_time).coinsides_with?(consistent_time..1.hour.from_now)
# |----|
# |----|
consistent_time = Time.zone.now
assert (consistent_time..1.hour.from_now).coinsides_with?(1.hour.ago..consistent_time)
# |---------|
# |---------|
assert (1.hour.ago..1.hour.from_now).coinsides_with?(2.hours.ago..Time.zone.now)
# |---------|
# |---------|
assert (2.hours.ago..Time.zone.now).coinsides_with?(1.hour.ago..1.hour.from_now)
# |----|
# |--------------|
assert (1.hour.ago..Time.zone.now).coinsides_with?(2.hours.ago..1.hour.from_now)
# |--------------|
# |----|
assert (2.hours.ago..1.hour.from_now).coinsides_with?(1.hour.ago..Time.zone.now)
# |----|
# |----|
refute (1.hour.ago..Time.zone.now).coinsides_with?(1.hour.from_now..2.hours.from_now)
# |----|
# |----|
refute (1.hour.from_now..2.hours.from_now).coinsides_with?(1.hour.ago..Time.zone.now)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment