PageRenderTime 34ms CodeModel.GetById 17ms app.highlight 13ms RepoModel.GetById 1ms app.codeStats 0ms

/vendor/bundle/jruby/2.1/gems/redis-3.0.7/test/commands_on_sets_test.rb

https://github.com/delowong/logstash
Ruby | 77 lines | 56 code | 20 blank | 1 comment | 0 complexity | a976df3efe6d7ee420e6a2c5e76b328c MD5 | raw file
 1# encoding: UTF-8
 2
 3require File.expand_path("helper", File.dirname(__FILE__))
 4require "lint/sets"
 5
 6class TestCommandsOnSets < Test::Unit::TestCase
 7
 8  include Helper::Client
 9  include Lint::Sets
10
11  def test_smove
12    r.sadd "foo", "s1"
13    r.sadd "bar", "s2"
14
15    assert r.smove("foo", "bar", "s1")
16    assert r.sismember("bar", "s1")
17  end
18
19  def test_sinter
20    r.sadd "foo", "s1"
21    r.sadd "foo", "s2"
22    r.sadd "bar", "s2"
23
24    assert_equal ["s2"], r.sinter("foo", "bar")
25  end
26
27  def test_sinterstore
28    r.sadd "foo", "s1"
29    r.sadd "foo", "s2"
30    r.sadd "bar", "s2"
31
32    r.sinterstore("baz", "foo", "bar")
33
34    assert_equal ["s2"], r.smembers("baz")
35  end
36
37  def test_sunion
38    r.sadd "foo", "s1"
39    r.sadd "foo", "s2"
40    r.sadd "bar", "s2"
41    r.sadd "bar", "s3"
42
43    assert_equal ["s1", "s2", "s3"], r.sunion("foo", "bar").sort
44  end
45
46  def test_sunionstore
47    r.sadd "foo", "s1"
48    r.sadd "foo", "s2"
49    r.sadd "bar", "s2"
50    r.sadd "bar", "s3"
51
52    r.sunionstore("baz", "foo", "bar")
53
54    assert_equal ["s1", "s2", "s3"], r.smembers("baz").sort
55  end
56
57  def test_sdiff
58    r.sadd "foo", "s1"
59    r.sadd "foo", "s2"
60    r.sadd "bar", "s2"
61    r.sadd "bar", "s3"
62
63    assert_equal ["s1"], r.sdiff("foo", "bar")
64    assert_equal ["s3"], r.sdiff("bar", "foo")
65  end
66
67  def test_sdiffstore
68    r.sadd "foo", "s1"
69    r.sadd "foo", "s2"
70    r.sadd "bar", "s2"
71    r.sadd "bar", "s3"
72
73    r.sdiffstore("baz", "foo", "bar")
74
75    assert_equal ["s1"], r.smembers("baz")
76  end
77end