package com.alibaba.json.bvt.util;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.util.AntiCollisionHashMap;
import junit.framework.TestCase;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class AntiCollisionHashMapTest extends TestCase {
    public void test_0() throws Exception {
        AntiCollisionHashMap m = new AntiCollisionHashMap(3, 0.75f);

        for (int i = 0; i < 100; ++i) {
            m.put(i, i);
        }

        AntiCollisionHashMap m2 = new AntiCollisionHashMap(m);
        assertEquals(m.size(), m2.size());

        AntiCollisionHashMap m3 = new AntiCollisionHashMap(3, 0.75f);
        m3.putAll(m);
        assertEquals(m.size(), m2.size());

        for (int i = 0; i < 100; ++i) {
            m3.remove(i);
            m2.remove(i, i);
        }

        {
            ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
            ObjectOutputStream objOut = new ObjectOutputStream(bytesOut);
            objOut.writeObject(m);
            objOut.flush();

            byte[] bytes = bytesOut.toByteArray();

            ByteArrayInputStream bytesIn = new ByteArrayInputStream(bytes);
            ObjectInputStream objIn = new ObjectInputStream(bytesIn);

            Object obj = objIn.readObject();

            assertEquals(AntiCollisionHashMap.class, obj.getClass());
            assertEquals(m, obj);
        }
    }
}

@@ -301,16 +301,43 @@
 tStream;
+%0Aimport java.util.Iterator;
 %0A%0Apublic
@@ -876,60 +876,600 @@
     
-m3.remove(i);%0A            m2.remove(i, i);%0A        %7D
+assertEquals(i, m.get(i));%0A            assertTrue(m.containsKey(i));%0A        %7D%0A%0A        for (int i = 0; i %3C 100; ++i) %7B%0A            m3.remove(i);%0A            m2.remove(i, i);%0A        %7D%0A        m2.put(null, null);%0A        m2.put(1, 1);%0A        assertTrue(m2.containsKey(null));%0A        assertTrue(m2.containsKey(1));%0A        Iterator iterator = m2.entrySet().iterator();%0A        while (iterator.hasNext()) %7B%0A            iterator.next();%0A            iterator.remove();%0A        %7D%0A        m2.clear();%0A%0A        m.entrySet().remove(1);%0A        m.entrySet().remove(m.entrySet().iterator().next());%0A%0A
 %0A%0A  

add testcase.