Skip to content

Commit 772cced

Browse files
author
Peter Wilhelmsson
committed
tests: Removed commented and duplicated tests
1 parent 0e4c5f6 commit 772cced

File tree

3 files changed

+154
-241
lines changed

3 files changed

+154
-241
lines changed

neo4j/test-integration/temporaltypes2_test.go

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package test_integration
2121

2222
import (
23+
"math"
2324
"math/rand"
2425
"testing"
2526
"time"
@@ -187,12 +188,165 @@ func TestTemporalTypes(tt *testing.T) {
187188
0, 0, 0, 0, time.Local))
188189
}
189190

191+
randomDuration := func() neo4j.Duration {
192+
sign := int64(1)
193+
if rand.Intn(2) == 0 {
194+
sign = -sign
195+
}
196+
197+
return neo4j.DurationOf(
198+
sign*rand.Int63n(math.MaxInt32),
199+
sign*rand.Int63n(math.MaxInt32),
200+
sign*rand.Int63n(math.MaxInt32),
201+
rand.Intn(1000000000))
202+
}
203+
204+
randomLocalTime := func() neo4j.LocalTime {
205+
return neo4j.LocalTimeOf(
206+
time.Date(
207+
0, 0, 0,
208+
rand.Intn(24),
209+
rand.Intn(60),
210+
rand.Intn(60),
211+
rand.Intn(1000000000),
212+
time.Local))
213+
}
214+
215+
randomLocalDateTime := func() neo4j.LocalDateTime {
216+
sign := 1
217+
if rand.Intn(2) == 0 {
218+
sign = -sign
219+
}
220+
221+
return neo4j.LocalDateTimeOf(
222+
time.Date(
223+
sign*rand.Intn(9999),
224+
time.Month(rand.Intn(12)+1),
225+
rand.Intn(28)+1,
226+
rand.Intn(24),
227+
rand.Intn(60),
228+
rand.Intn(60),
229+
rand.Intn(1000000000),
230+
time.Local))
231+
}
232+
233+
randomOffsetTime := func() neo4j.OffsetTime {
234+
sign := 1
235+
if rand.Intn(2) == 0 {
236+
sign = -sign
237+
}
238+
239+
return neo4j.OffsetTimeOf(
240+
time.Date(
241+
0, 0, 0,
242+
rand.Intn(24),
243+
rand.Intn(60),
244+
rand.Intn(60),
245+
rand.Intn(1000000000),
246+
time.FixedZone("Offset", sign*rand.Intn(64800))))
247+
}
248+
randomOffsetDateTime := func() time.Time {
249+
sign := 1
250+
if rand.Intn(2) == 0 {
251+
sign = -sign
252+
}
253+
254+
return time.Date(
255+
rand.Intn(300)+1900,
256+
time.Month(rand.Intn(12)+1),
257+
rand.Intn(28)+1,
258+
rand.Intn(24),
259+
rand.Intn(60),
260+
rand.Intn(60),
261+
rand.Intn(1000000000),
262+
time.FixedZone("Offset", sign*rand.Intn(64800)))
263+
}
264+
265+
randomZonedDateTime := func() time.Time {
266+
var zones = []string{
267+
"Africa/Harare", "America/Aruba", "Africa/Nairobi", "America/Dawson", "Asia/Beirut", "Asia/Tashkent",
268+
"Canada/Eastern", "Europe/Malta", "Europe/Volgograd", "Indian/Kerguelen", "Etc/GMT+3",
269+
}
270+
271+
location, err := time.LoadLocation(zones[rand.Intn(len(zones))])
272+
if err != nil {
273+
panic(err)
274+
}
275+
276+
return time.Date(
277+
rand.Intn(300)+1900,
278+
time.Month(rand.Intn(12)+1),
279+
rand.Intn(28)+1,
280+
rand.Intn(17)+6, // to be safe from DST changes
281+
rand.Intn(60),
282+
rand.Intn(60),
283+
rand.Intn(1000000000),
284+
location)
285+
}
286+
190287
rt.Run("Date", func(t *testing.T) {
191288
for i := 0; i < numRand; i++ {
192289
d1 := randomDate()
193290
d2 := sendAndReceive(t, d1).(neo4j.Date)
194291
assertDatePart(t, time.Time(d1), time.Time(d2))
195292
}
196293
})
294+
295+
rt.Run("Duration", func(t *testing.T) {
296+
for i := 0; i < numRand; i++ {
297+
d1 := randomDuration()
298+
d2 := sendAndReceive(t, d1).(neo4j.Duration)
299+
assertDurationEqual(t, d1, d2)
300+
}
301+
})
302+
303+
rt.Run("LocalTime", func(t *testing.T) {
304+
for i := 0; i < numRand; i++ {
305+
d1 := randomLocalTime()
306+
d2 := sendAndReceive(t, d1).(neo4j.LocalTime)
307+
assertTimePart(t, time.Time(d1), time.Time(d2))
308+
assertLocal(t, time.Time(d2))
309+
}
310+
})
311+
312+
rt.Run("OffsetTime", func(t *testing.T) {
313+
for i := 0; i < numRand; i++ {
314+
d1 := randomOffsetTime()
315+
d2 := sendAndReceive(t, d1).(neo4j.OffsetTime)
316+
assertTimePart(t, time.Time(d1), time.Time(d2))
317+
assertZone(t, time.Time(d2), "Offset")
318+
}
319+
})
320+
321+
rt.Run("LocalDateTime", func(t *testing.T) {
322+
for i := 0; i < numRand; i++ {
323+
d1 := randomLocalDateTime()
324+
d2 := sendAndReceive(t, d1).(neo4j.LocalDateTime)
325+
assertDatePart(t, time.Time(d1), time.Time(d2))
326+
assertTimePart(t, time.Time(d1), time.Time(d2))
327+
assertLocal(t, time.Time(d2))
328+
}
329+
})
330+
331+
rt.Run("Offset DateTime", func(t *testing.T) {
332+
for i := 0; i < numRand; i++ {
333+
d1 := randomOffsetDateTime()
334+
d2 := sendAndReceive(t, d1).(time.Time)
335+
assertDatePart(t, d1, d2)
336+
assertTimePart(t, d1, d2)
337+
assertZone(t, d2, "Offset")
338+
}
339+
})
340+
341+
rt.Run("Zoned DateTime", func(t *testing.T) {
342+
for i := 0; i < numRand; i++ {
343+
d1 := randomZonedDateTime()
344+
d2 := sendAndReceive(t, d1).(time.Time)
345+
assertDatePart(t, d1, d2)
346+
assertTimePart(t, d1, d2)
347+
zone, _ := d1.Zone()
348+
assertZone(t, d2, zone)
349+
}
350+
})
197351
})
198352
}

neo4j/test-integration/temporaltypes_test.go

Lines changed: 0 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -176,19 +176,6 @@ var _ = Describe("Temporal Types", func() {
176176
location)
177177
}
178178

179-
testReceive := func(query string, expected interface{}) {
180-
result, err = session.Run(query, nil)
181-
Expect(err).To(BeNil())
182-
183-
if result.Next() {
184-
var received = result.Record().Values[0]
185-
186-
Expect(received).To(Equal(expected))
187-
}
188-
Expect(result.Err()).To(BeNil())
189-
Expect(result.Next()).To(BeFalse())
190-
}
191-
192179
testSendAndReceive := func(query string, data interface{}, expected []interface{}) {
193180
result, err = session.Run(query, map[string]interface{}{"x": data})
194181
Expect(err).To(BeNil())
@@ -228,43 +215,6 @@ var _ = Describe("Temporal Types", func() {
228215
Expect(result.Next()).To(BeFalse())
229216
}
230217

231-
Context("Receive", func() {
232-
It("duration", func() {
233-
testReceive("RETURN duration({ months: 16, days: 45, seconds: 120, nanoseconds: 187309812 })", neo4j.DurationOf(16, 45, 120, 187309812))
234-
})
235-
236-
It("date", func() {
237-
testReceive("RETURN date({ year: 1994, month: 11, day: 15 })", neo4j.DateOf(time.Date(1994, 11, 15, 0, 0, 0, 0, time.Local)))
238-
})
239-
240-
It("local time", func() {
241-
testReceive("RETURN localtime({ hour: 23, minute: 49, second: 59, nanosecond: 999999999 })", neo4j.LocalTimeOf(time.Date(0, 0, 0, 23, 49, 59, 999999999, time.Local)))
242-
})
243-
244-
It("offset time", func() {
245-
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))))
246-
})
247-
248-
It("local date time (test location = UTC)", func() {
249-
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)))
250-
})
251-
252-
It("local date time (test location = local)", func() {
253-
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)))
254-
})
255-
256-
It("offset date time", func() {
257-
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)))
258-
})
259-
260-
It("zoned date time", func() {
261-
location, err := time.LoadLocation("Europe/London")
262-
Expect(err).To(BeNil())
263-
264-
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))
265-
})
266-
})
267-
268218
Context("Send and Receive", func() {
269219
It("duration", func() {
270220
data := neo4j.DurationOf(14, 35, 75, 789012587)
@@ -390,55 +340,6 @@ var _ = Describe("Temporal Types", func() {
390340
})
391341
})
392342

393-
Context("Send and receive random", func() {
394-
It("duration", func() {
395-
for i := 0; i < numberOfRandomValues; i++ {
396-
testSendAndReceiveValue(randomDuration())
397-
}
398-
})
399-
400-
It("date", func() {
401-
for i := 0; i < numberOfRandomValues; i++ {
402-
testSendAndReceiveValue(randomLocalDate())
403-
}
404-
})
405-
406-
It("local time", func() {
407-
for i := 0; i < numberOfRandomValues; i++ {
408-
testSendAndReceiveValue(randomLocalTime())
409-
}
410-
})
411-
412-
It("offset time", func() {
413-
for i := 0; i < numberOfRandomValues; i++ {
414-
testSendAndReceiveValue(randomOffsetTime())
415-
}
416-
})
417-
418-
It("local date time", func() {
419-
for i := 0; i < numberOfRandomValues; i++ {
420-
testSendAndReceiveValueComp(randomLocalDateTime(), func(x, y interface{}) bool {
421-
x1 := x.(neo4j.LocalDateTime)
422-
y1 := y.(neo4j.LocalDateTime)
423-
424-
return x1.Time().Equal(y1.Time())
425-
})
426-
}
427-
})
428-
429-
It("offset date time", func() {
430-
for i := 0; i < numberOfRandomValues; i++ {
431-
testSendAndReceiveValue(randomOffsetDateTime())
432-
}
433-
})
434-
435-
It("zoned date time", func() {
436-
for i := 0; i < numberOfRandomValues; i++ {
437-
testSendAndReceiveValue(randomZonedDateTime())
438-
}
439-
})
440-
})
441-
442343
Context("Send and receive random arrays", func() {
443344
It("duration", func() {
444345
listSize := rand.Intn(1000)

0 commit comments

Comments
 (0)