Skip to content

Commit 4351e18

Browse files
committed
Added unit tests, simplified quick check
1 parent 80e9a66 commit 4351e18

File tree

2 files changed

+41
-5
lines changed

2 files changed

+41
-5
lines changed

inst/demos/queueDemo.R

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,17 @@ quickCheck <- function() {
133133
redis <- new(RcppRedis::Redis)
134134
redis$lpush("foo", "banana")
135135
redis$lpush("foo", "banana")
136-
print(str(redis$lrange("foo", 0, -1)))
136+
#print(str(redis$lrange("foo", 0, -1)))
137+
print(redis$llen("foo"))
137138
redis$lrem("foo", 1, "banana")
138-
print(str(redis$lrange("foo", 0, -1)))
139+
#print(str(redis$lrange("foo", 0, -1)))
140+
print(redis$llen("foo"))
139141
redis$lpop("foo")
140-
print(str(redis$lrange("foo", 0, -1)))
142+
#print(str(redis$lrange("foo", 0, -1)))
143+
print(redis$llen("foo"))
141144
invisible(NULL)
142145
}
143146

144-
useRcppRedis()
147+
#useRcppRedis()
145148
#useRedux()
146-
#quickCheck()
149+
quickCheck()

inst/tinytest/test_list.R

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,36 @@ redis$exec(paste("del", key))
6767
## delete key
6868
n <- redis$exec(paste("del", key))
6969
expect_equal(n, 0)
70+
71+
72+
## check lrem
73+
redis$exec(paste("del", key))
74+
elem <- "abc"
75+
redis$lpush(key, elem)
76+
redis$lpush(key, elem)
77+
redis$lpush(key, elem)
78+
redis$lpush(key, elem)
79+
expect_equal(redis$llen(key), 4)
80+
redis$lrem(key, 1, elem)
81+
expect_equal(redis$llen(key), 3)
82+
redis$lrem(key, -1, elem)
83+
expect_equal(redis$llen(key), 2)
84+
expect_equal(redis$lpop(key), elem)
85+
expect_equal(redis$lpop(key), elem)
86+
expect_equal(redis$keys(key), character())
87+
88+
## check lmove
89+
altkey <- "RcppRedis:test:myotherlist"
90+
redis$exec(paste("del", altkey))
91+
redis$rpush(key, 1)
92+
redis$rpush(key, 2)
93+
redis$rpush(key, 3)
94+
redis$lmove(key, altkey, "LEFT", "RIGHT")
95+
expect_equal(redis$llen(key), 2)
96+
expect_equal(redis$llen(altkey), 1)
97+
redis$lmove(key, altkey, "LEFT", "LEFT")
98+
expect_equal(redis$llen(key), 1)
99+
expect_equal(redis$llen(altkey), 2)
100+
expect_equal(redis$lpop(key), 3) # as 1 and 2 have been moved (both from left)
101+
expect_equal(redis$lpop(altkey), 2) # as 2 was inserted to the left
102+
expect_equal(redis$lpop(altkey), 1) # as 1 remains

0 commit comments

Comments
 (0)