Skip to content

Commit

Permalink
tests: Removed commented and duplicated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Wilhelmsson committed Dec 3, 2020
1 parent 0e4c5f6 commit 772cced
Show file tree
Hide file tree
Showing 3 changed files with 154 additions and 241 deletions.
154 changes: 154 additions & 0 deletions neo4j/test-integration/temporaltypes2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package test_integration

import (
"math"
"math/rand"
"testing"
"time"
Expand Down Expand Up @@ -187,12 +188,165 @@ func TestTemporalTypes(tt *testing.T) {
0, 0, 0, 0, time.Local))
}

randomDuration := func() neo4j.Duration {
sign := int64(1)
if rand.Intn(2) == 0 {
sign = -sign
}

return neo4j.DurationOf(
sign*rand.Int63n(math.MaxInt32),
sign*rand.Int63n(math.MaxInt32),
sign*rand.Int63n(math.MaxInt32),
rand.Intn(1000000000))
}

randomLocalTime := func() neo4j.LocalTime {
return neo4j.LocalTimeOf(
time.Date(
0, 0, 0,
rand.Intn(24),
rand.Intn(60),
rand.Intn(60),
rand.Intn(1000000000),
time.Local))
}

randomLocalDateTime := func() neo4j.LocalDateTime {
sign := 1
if rand.Intn(2) == 0 {
sign = -sign
}

return neo4j.LocalDateTimeOf(
time.Date(
sign*rand.Intn(9999),
time.Month(rand.Intn(12)+1),
rand.Intn(28)+1,
rand.Intn(24),
rand.Intn(60),
rand.Intn(60),
rand.Intn(1000000000),
time.Local))
}

randomOffsetTime := func() neo4j.OffsetTime {
sign := 1
if rand.Intn(2) == 0 {
sign = -sign
}

return neo4j.OffsetTimeOf(
time.Date(
0, 0, 0,
rand.Intn(24),
rand.Intn(60),
rand.Intn(60),
rand.Intn(1000000000),
time.FixedZone("Offset", sign*rand.Intn(64800))))
}
randomOffsetDateTime := func() time.Time {
sign := 1
if rand.Intn(2) == 0 {
sign = -sign
}

return time.Date(
rand.Intn(300)+1900,
time.Month(rand.Intn(12)+1),
rand.Intn(28)+1,
rand.Intn(24),
rand.Intn(60),
rand.Intn(60),
rand.Intn(1000000000),
time.FixedZone("Offset", sign*rand.Intn(64800)))
}

randomZonedDateTime := func() time.Time {
var zones = []string{
"Africa/Harare", "America/Aruba", "Africa/Nairobi", "America/Dawson", "Asia/Beirut", "Asia/Tashkent",
"Canada/Eastern", "Europe/Malta", "Europe/Volgograd", "Indian/Kerguelen", "Etc/GMT+3",
}

location, err := time.LoadLocation(zones[rand.Intn(len(zones))])
if err != nil {
panic(err)
}

return time.Date(
rand.Intn(300)+1900,
time.Month(rand.Intn(12)+1),
rand.Intn(28)+1,
rand.Intn(17)+6, // to be safe from DST changes
rand.Intn(60),
rand.Intn(60),
rand.Intn(1000000000),
location)
}

rt.Run("Date", func(t *testing.T) {
for i := 0; i < numRand; i++ {
d1 := randomDate()
d2 := sendAndReceive(t, d1).(neo4j.Date)
assertDatePart(t, time.Time(d1), time.Time(d2))
}
})

rt.Run("Duration", func(t *testing.T) {
for i := 0; i < numRand; i++ {
d1 := randomDuration()
d2 := sendAndReceive(t, d1).(neo4j.Duration)
assertDurationEqual(t, d1, d2)
}
})

rt.Run("LocalTime", func(t *testing.T) {
for i := 0; i < numRand; i++ {
d1 := randomLocalTime()
d2 := sendAndReceive(t, d1).(neo4j.LocalTime)
assertTimePart(t, time.Time(d1), time.Time(d2))
assertLocal(t, time.Time(d2))
}
})

rt.Run("OffsetTime", func(t *testing.T) {
for i := 0; i < numRand; i++ {
d1 := randomOffsetTime()
d2 := sendAndReceive(t, d1).(neo4j.OffsetTime)
assertTimePart(t, time.Time(d1), time.Time(d2))
assertZone(t, time.Time(d2), "Offset")
}
})

rt.Run("LocalDateTime", func(t *testing.T) {
for i := 0; i < numRand; i++ {
d1 := randomLocalDateTime()
d2 := sendAndReceive(t, d1).(neo4j.LocalDateTime)
assertDatePart(t, time.Time(d1), time.Time(d2))
assertTimePart(t, time.Time(d1), time.Time(d2))
assertLocal(t, time.Time(d2))
}
})

rt.Run("Offset DateTime", func(t *testing.T) {
for i := 0; i < numRand; i++ {
d1 := randomOffsetDateTime()
d2 := sendAndReceive(t, d1).(time.Time)
assertDatePart(t, d1, d2)
assertTimePart(t, d1, d2)
assertZone(t, d2, "Offset")
}
})

rt.Run("Zoned DateTime", func(t *testing.T) {
for i := 0; i < numRand; i++ {
d1 := randomZonedDateTime()
d2 := sendAndReceive(t, d1).(time.Time)
assertDatePart(t, d1, d2)
assertTimePart(t, d1, d2)
zone, _ := d1.Zone()
assertZone(t, d2, zone)
}
})
})
}
99 changes: 0 additions & 99 deletions neo4j/test-integration/temporaltypes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,19 +176,6 @@ var _ = Describe("Temporal Types", func() {
location)
}

testReceive := func(query string, expected interface{}) {
result, err = session.Run(query, nil)
Expect(err).To(BeNil())

if result.Next() {
var received = result.Record().Values[0]

Expect(received).To(Equal(expected))
}
Expect(result.Err()).To(BeNil())
Expect(result.Next()).To(BeFalse())
}

testSendAndReceive := func(query string, data interface{}, expected []interface{}) {
result, err = session.Run(query, map[string]interface{}{"x": data})
Expect(err).To(BeNil())
Expand Down Expand Up @@ -228,43 +215,6 @@ var _ = Describe("Temporal Types", func() {
Expect(result.Next()).To(BeFalse())
}

Context("Receive", func() {
It("duration", func() {
testReceive("RETURN duration({ months: 16, days: 45, seconds: 120, nanoseconds: 187309812 })", neo4j.DurationOf(16, 45, 120, 187309812))
})

It("date", func() {
testReceive("RETURN date({ year: 1994, month: 11, day: 15 })", neo4j.DateOf(time.Date(1994, 11, 15, 0, 0, 0, 0, time.Local)))
})

It("local time", func() {
testReceive("RETURN localtime({ hour: 23, minute: 49, second: 59, nanosecond: 999999999 })", neo4j.LocalTimeOf(time.Date(0, 0, 0, 23, 49, 59, 999999999, time.Local)))
})

It("offset time", func() {
testReceive("RETURN time({ hour: 23, minute: 49, second: 59, nanosecond: 999999999, timezone:'+03:00' })", neo4j.OffsetTimeOf(time.Date(0, 0, 0, 23, 49, 59, 999999999, time.FixedZone("Offset", 3*60*60))))
})

It("local date time (test location = UTC)", func() {
testReceive("RETURN localdatetime({ year: 1859, month: 5, day: 31, hour: 23, minute: 49, second: 59, nanosecond: 999999999 })", neo4j.LocalDateTimeOf(time.Date(1859, 5, 31, 23, 49, 59, 999999999, time.UTC)))
})

It("local date time (test location = local)", func() {
testReceive("RETURN localdatetime({ year: 1859, month: 5, day: 31, hour: 23, minute: 49, second: 59, nanosecond: 999999999 })", neo4j.LocalDateTimeOf(time.Date(1859, 5, 31, 23, 49, 59, 999999999, time.Local)))
})

It("offset date time", func() {
testReceive("RETURN datetime({ year: 1859, month: 5, day: 31, hour: 23, minute: 49, second: 59, nanosecond: 999999999, timezone:'+02:30' })", time.Date(1859, 5, 31, 23, 49, 59, 999999999, time.FixedZone("Offset", 150*60)))
})

It("zoned date time", func() {
location, err := time.LoadLocation("Europe/London")
Expect(err).To(BeNil())

testReceive("RETURN datetime({ year: 1959, month: 5, day: 31, hour: 23, minute: 49, second: 59, nanosecond: 999999999, timezone:'Europe/London' })", time.Date(1959, 5, 31, 23, 49, 59, 999999999, location))
})
})

Context("Send and Receive", func() {
It("duration", func() {
data := neo4j.DurationOf(14, 35, 75, 789012587)
Expand Down Expand Up @@ -390,55 +340,6 @@ var _ = Describe("Temporal Types", func() {
})
})

Context("Send and receive random", func() {
It("duration", func() {
for i := 0; i < numberOfRandomValues; i++ {
testSendAndReceiveValue(randomDuration())
}
})

It("date", func() {
for i := 0; i < numberOfRandomValues; i++ {
testSendAndReceiveValue(randomLocalDate())
}
})

It("local time", func() {
for i := 0; i < numberOfRandomValues; i++ {
testSendAndReceiveValue(randomLocalTime())
}
})

It("offset time", func() {
for i := 0; i < numberOfRandomValues; i++ {
testSendAndReceiveValue(randomOffsetTime())
}
})

It("local date time", func() {
for i := 0; i < numberOfRandomValues; i++ {
testSendAndReceiveValueComp(randomLocalDateTime(), func(x, y interface{}) bool {
x1 := x.(neo4j.LocalDateTime)
y1 := y.(neo4j.LocalDateTime)

return x1.Time().Equal(y1.Time())
})
}
})

It("offset date time", func() {
for i := 0; i < numberOfRandomValues; i++ {
testSendAndReceiveValue(randomOffsetDateTime())
}
})

It("zoned date time", func() {
for i := 0; i < numberOfRandomValues; i++ {
testSendAndReceiveValue(randomZonedDateTime())
}
})
})

Context("Send and receive random arrays", func() {
It("duration", func() {
listSize := rand.Intn(1000)
Expand Down
Loading

0 comments on commit 772cced

Please sign in to comment.