package redis.clients.jedis.tests;

import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;

import org.junit.Test;

import redis.clients.jedis.Tuple;
import redis.clients.jedis.tests.commands.JedisCommandTestBase;

import static org.junit.Assert.assertEquals;

public class TupleSortedSetTest extends JedisCommandTestBase {
  final byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 };
  final byte[] ba = { 0x0A };
  final byte[] bb = { 0x0B };
  final byte[] bc = { 0x0C };
  final byte[] bd = { 0x0D };

  @Test
  public void testBinary() {
    SortedSet<Tuple> sortedSet = new TreeSet<Tuple>();

    jedis.zadd(bfoo, 0d, ba);
    sortedSet.add(new Tuple(ba, 0d));

    jedis.zadd(bfoo, 1d, bb);
    sortedSet.add(new Tuple(bb, 1d));

    Set<Tuple> zrange = jedis.zrangeWithScores(bfoo, 0, -1);
    assertEquals(sortedSet, zrange);

    jedis.zadd(bfoo, -0.3, bc);
    sortedSet.add(new Tuple(bc, -0.3));

    jedis.zadd(bfoo, 0.3, bd);
    sortedSet.add(new Tuple(bd, 0.3));

    zrange = jedis.zrangeWithScores(bfoo, 0, -1);
    assertEquals(sortedSet, zrange);
  }

  @Test
  public void testString() {
    SortedSet<Tuple> sortedSet = new TreeSet<Tuple>();

    jedis.zadd("foo", 0d, "a");
    sortedSet.add(new Tuple("a", 0d));

    jedis.zadd("foo", 1d, "b");
    sortedSet.add(new Tuple("b", 1d));

    Set<Tuple> range = jedis.zrangeWithScores("foo", 0, -1);
    assertEquals(sortedSet, range);

    jedis.zadd("foo", -0.3, "c");
    sortedSet.add(new Tuple("c", -0.3));

    jedis.zadd("foo", 0.3, "d");
    sortedSet.add(new Tuple("d", 0.3));

    range = jedis.zrangeWithScores("foo", 0, -1);
    assertEquals(sortedSet, range);
  }
}

@@ -29,16 +29,62 @@
 tests;%0A%0A
+import static org.junit.Assert.assertEquals;%0A%0A
 import j
@@ -93,24 +93,24 @@
 a.util.Set;%0A
-
 import java.
@@ -279,54 +279,8 @@
 e;%0A%0A
-import static org.junit.Assert.assertEquals;%0A%0A
 publ
@@ -507,16 +507,76 @@
  0x0D %7D;
+%0A  final byte%5B%5D be = %7B 0x0E %7D;%0A  final byte%5B%5D bf = %7B 0x0F %7D;
 %0A%0A  @Tes
@@ -964,32 +964,174 @@
 le(bc, -0.3));%0A%0A
+    jedis.zadd(bfoo, 0.3, bf);%0A    sortedSet.add(new Tuple(bf, 0.3));%0A%0A    jedis.zadd(bfoo, 0.3, be);%0A    sortedSet.add(new Tuple(be, 0.3));%0A%0A
     jedis.zadd(b
@@ -1642,24 +1642,24 @@
 -0.3, %22c%22);%0A
-
     sortedSe
@@ -1680,32 +1680,180 @@
 e(%22c%22, -0.3));%0A%0A
+    jedis.zadd(%22foo%22, 0.3, %22f%22);%0A    sortedSet.add(new Tuple(%22f%22, 0.3));%0A%0A    jedis.zadd(%22foo%22, 0.3, %22e%22);%0A    sortedSet.add(new Tuple(%22e%22, 0.3));%0A%0A
     jedis.zadd(%22

Test added for multiple elements with same score.