From ba246d693d05e69e6693b95e74606923a335d0de Mon Sep 17 00:00:00 2001 From: Masashi Umezawa Date: Wed, 24 Jul 2024 00:36:52 +0900 Subject: [PATCH] Added StreamReverseIterator test cases --- .../instance/testNextAtMost.st | 27 +++++++++++++++++++ .../instance/testReversedDoCollect.st | 27 +++++++++++++++++++ .../instance/testReversedNextAtMost.st | 27 +++++++++++++++++++ .../instance/previousAtMost.after..st | 2 +- .../instance/reversed.st | 3 +++ .../instance/reversed.st | 3 +++ 6 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 repository/RediStick-Stream-Objects-Tests.package/RsRedisStreamIteratorTest.class/instance/testNextAtMost.st create mode 100644 repository/RediStick-Stream-Objects-Tests.package/RsRedisStreamIteratorTest.class/instance/testReversedDoCollect.st create mode 100644 repository/RediStick-Stream-Objects-Tests.package/RsRedisStreamIteratorTest.class/instance/testReversedNextAtMost.st create mode 100644 repository/RediStick-Stream-Objects.package/RsStreamIterator.class/instance/reversed.st create mode 100644 repository/RediStick-Stream-Objects.package/RsStreamReverseIterator.class/instance/reversed.st diff --git a/repository/RediStick-Stream-Objects-Tests.package/RsRedisStreamIteratorTest.class/instance/testNextAtMost.st b/repository/RediStick-Stream-Objects-Tests.package/RsRedisStreamIteratorTest.class/instance/testNextAtMost.st new file mode 100644 index 0000000..d08977e --- /dev/null +++ b/repository/RediStick-Stream-Objects-Tests.package/RsRedisStreamIteratorTest.class/instance/testNextAtMost.st @@ -0,0 +1,27 @@ +tests +testNextAtMost + | strm one two three four five ite1 entries1 ite2 entries2 | + strm := self newStreamNamed: 'testNextAtMost'. + strm trimTo: 0. + self assert: strm length equals: 0. + one := 'one' -> '1'. + two := 'two' -> '2'. + three := 'three' -> '3'. + four := 'four' -> '4'. + five := 'five' -> '5'. + strm << one << two << three << four << five. + ite1 := strm iteratorFromFirst. + self assert: strm first content equals: one. + entries1 := OrderedCollection new. + ite1 nextAtMost: 2 do: [ :each | entries1 add: each ]. + self assert: entries1 size equals: 2. + self assert: entries1 first content equals: two. + self assert: entries1 second content equals: three. + ite2 := strm iteratorFrom: entries1 second. + entries2 := OrderedCollection new. + ite2 nextAtMost: 5 do: [ :each | entries2 add: each ]. + self assert: entries2 size equals: 2. + self assert: entries2 first content equals: four. + self assert: entries2 last content equals: five. + strm trimTo: 0. + self assert: strm length equals: 0. \ No newline at end of file diff --git a/repository/RediStick-Stream-Objects-Tests.package/RsRedisStreamIteratorTest.class/instance/testReversedDoCollect.st b/repository/RediStick-Stream-Objects-Tests.package/RsRedisStreamIteratorTest.class/instance/testReversedDoCollect.st new file mode 100644 index 0000000..8496300 --- /dev/null +++ b/repository/RediStick-Stream-Objects-Tests.package/RsRedisStreamIteratorTest.class/instance/testReversedDoCollect.st @@ -0,0 +1,27 @@ +tests +testReversedDoCollect + | strm one two three four five ite1 entries1 ite2 entries2 | + strm := self newStreamNamed: 'testReversedDoCollect'. + strm trimTo: 0. + self assert: strm length equals: 0. + one := 'one' -> '1'. + two := 'two' -> '2'. + three := 'three' -> '3'. + four := 'four' -> '4'. + five := 'five' -> '5'. + strm << one << two << three << four << five. + ite1 := strm iteratorFromLast reversed. + self assert: strm last content equals: five. + entries1 := OrderedCollection new. + ite1 do: [ :each | entries1 add: each ]. + self assert: entries1 size equals: 4. + self assert: entries1 first content equals: four. + self assert: entries1 second content equals: three. + self assert: entries1 last content equals: one. + ite2 := (strm iteratorFrom: entries1 second) reversed. + entries2 := ite2 collect: [ :each | each ]. + self assert: entries2 size equals: 2. + self assert: entries2 first content equals: two. + self assert: entries2 last content equals: one. + strm trimTo: 0. + self assert: strm length equals: 0. \ No newline at end of file diff --git a/repository/RediStick-Stream-Objects-Tests.package/RsRedisStreamIteratorTest.class/instance/testReversedNextAtMost.st b/repository/RediStick-Stream-Objects-Tests.package/RsRedisStreamIteratorTest.class/instance/testReversedNextAtMost.st new file mode 100644 index 0000000..092a726 --- /dev/null +++ b/repository/RediStick-Stream-Objects-Tests.package/RsRedisStreamIteratorTest.class/instance/testReversedNextAtMost.st @@ -0,0 +1,27 @@ +tests +testReversedNextAtMost + | strm one two three four five ite1 entries1 ite2 entries2 | + strm := self newStreamNamed: 'testReversedNextAtMost'. + strm trimTo: 0. + self assert: strm length equals: 0. + one := 'one' -> '1'. + two := 'two' -> '2'. + three := 'three' -> '3'. + four := 'four' -> '4'. + five := 'five' -> '5'. + strm << one << two << three << four << five. + ite1 := strm iteratorFromLast reversed. + self assert: strm last content equals: five. + entries1 := OrderedCollection new. + ite1 nextAtMost: 2 do: [ :each | entries1 add: each ]. + self assert: entries1 size equals: 2. + self assert: entries1 first content equals: four. + self assert: entries1 second content equals: three. + ite2 := (strm iteratorFrom: entries1 second) reversed. + entries2 := OrderedCollection new. + ite2 nextAtMost: 5 do: [ :each | entries2 add: each ]. + self assert: entries2 size equals: 2. + self assert: entries2 first content equals: two. + self assert: entries2 last content equals: one. + strm trimTo: 0. + self assert: strm length equals: 0. \ No newline at end of file diff --git a/repository/RediStick-Stream-Objects.package/RsStream.class/instance/previousAtMost.after..st b/repository/RediStick-Stream-Objects.package/RsStream.class/instance/previousAtMost.after..st index 2f5dd1f..37ba9c1 100644 --- a/repository/RediStick-Stream-Objects.package/RsStream.class/instance/previousAtMost.after..st +++ b/repository/RediStick-Stream-Objects.package/RsStream.class/instance/previousAtMost.after..st @@ -1,3 +1,3 @@ reading previousAtMost: count after: latestMessageId - ^ self endpoint xRevRange: self name from: latestMessageId count: count \ No newline at end of file + ^ self endpoint xRevRange: self name nextFrom: latestMessageId count: count \ No newline at end of file diff --git a/repository/RediStick-Stream-Objects.package/RsStreamIterator.class/instance/reversed.st b/repository/RediStick-Stream-Objects.package/RsStreamIterator.class/instance/reversed.st new file mode 100644 index 0000000..07b2cfd --- /dev/null +++ b/repository/RediStick-Stream-Objects.package/RsStreamIterator.class/instance/reversed.st @@ -0,0 +1,3 @@ +converting +reversed + ^ RsStreamReverseIterator on: self stream from: self currentId \ No newline at end of file diff --git a/repository/RediStick-Stream-Objects.package/RsStreamReverseIterator.class/instance/reversed.st b/repository/RediStick-Stream-Objects.package/RsStreamReverseIterator.class/instance/reversed.st new file mode 100644 index 0000000..230e02c --- /dev/null +++ b/repository/RediStick-Stream-Objects.package/RsStreamReverseIterator.class/instance/reversed.st @@ -0,0 +1,3 @@ +converting +reversed + ^ RsStreamIterator on: self stream from: self currentId \ No newline at end of file