package com.abominableshrine.taptounlock;

import android.os.Bundle;

import junit.framework.TestCase;

public class TapPatternTest extends TestCase {

    public void testEmptyPatternSizeDuration() {
        TapPattern p = new TapPattern();
        assertEquals(0, p.size());
        assertEquals(0, p.duration());
    }

    public void testSingleTapPatternDuration() {
        TapPattern p = new TapPattern();
        assertNotNull(p.appendTap(TapPattern.DeviceSide.BACK, 10));
        assertEquals(1, p.size());
        assertEquals(0, p.duration());
    }

    public void testNullOnNegativeDuration() {
        TapPattern p = new TapPattern().appendTap(TapPattern.DeviceSide.TOP, 10);
        assertNull(p.appendTap(TapPattern.DeviceSide.FRONT, -1));
    }

    public void testIgnorePauseFirstTap() {
        assertNotNull(new TapPattern().appendTap(TapPattern.DeviceSide.LEFT, 0));
        assertNotNull(new TapPattern().appendTap(TapPattern.DeviceSide.LEFT, -20));
    }

    public void testNullOnZeroDuration() {
        TapPattern p = new TapPattern();
        TapPattern p1 = p.appendTap(TapPattern.DeviceSide.LEFT, 10);
        assertNotNull(p1);
        assertNull(p1.appendTap(TapPattern.DeviceSide.FRONT, 0));
    }

    private void fillComplexPattern(TapPattern p) {
        p.appendTap(TapPattern.DeviceSide.FRONT, 10)
                .appendTap(TapPattern.DeviceSide.TOP, 10)
                .appendTap(TapPattern.DeviceSide.BOTTOM, 10);
    }

    public void testSizeDurationLongPattern() {
        TapPattern p = new TapPattern();
        fillComplexPattern(p);
        assertEquals(3, p.size());
        assertEquals(20, p.duration());
    }

    public void testNotEqualsSingleAndEmptyPattern() {
        TapPattern emptyPattern = new TapPattern();
        TapPattern singlePattern = new TapPattern().appendTap(TapPattern.DeviceSide.LEFT, 10);
        assertFalse(emptyPattern.equals(singlePattern));
    }

    public void testNotEqualsDifferentSides() {
        TapPattern rightTap = new TapPattern().appendTap(TapPattern.DeviceSide.RIGHT, 1);
        TapPattern leftTap = new TapPattern().appendTap(TapPattern.DeviceSide.LEFT, 1);
        assertFalse(leftTap.equals(rightTap));
    }

    public void testEqualComplexPattern() {
        TapPattern p1 = new TapPattern();
        TapPattern p2 = new TapPattern();
        fillComplexPattern(p1);
        fillComplexPattern(p2);
        assertEquals(p1, p2);
    }

    public void testBundleRoundTrip() {
        TapPattern p1 = new TapPattern();
        fillComplexPattern(p1);
        Bundle b = p1.toBundle();
        assertEquals(p1, new TapPattern(b));
    }
}

@@ -145,16 +145,163 @@
 Case %7B%0A%0A
+    private TapPattern p;%0A%0A    @Override%0A    protected void setUp() throws Exception %7B%0A        super.setUp();%0A        p = new TapPattern();%0A    %7D%0A%0A
     publ
@@ -345,49 +345,8 @@
 ) %7B%0A
-        TapPattern p = new TapPattern();%0A
     
@@ -475,49 +475,8 @@
 ) %7B%0A
-        TapPattern p = new TapPattern();%0A
     
@@ -679,39 +679,9 @@
     
-TapPattern p = new TapPattern()
+p
 .app
@@ -1056,49 +1056,8 @@
 ) %7B%0A
-        TapPattern p = new TapPattern();%0A
     
@@ -1505,49 +1505,8 @@
 ) %7B%0A
-        TapPattern p = new TapPattern();%0A
     
@@ -2258,39 +2258,27 @@
     
-TapPattern p2 = new Tap
+fillComplex
 Pattern(
 );%0A 
@@ -2265,32 +2265,33 @@
 lComplexPattern(
+p
 );%0A        fillC
@@ -2321,29 +2321,137 @@
     
-fillComplexPattern(p2
+assertEquals(p1, p);%0A    %7D%0A%0A    public void testBundleRoundTrip() %7B%0A        fillComplexPattern(p);%0A        Bundle b = p.toBundle(
 );%0A 
@@ -2475,13 +2475,27 @@
 ls(p
-1
 , 
-p2
+new TapPattern(b)
 );%0A 
@@ -2512,32 +2512,37 @@
 public void test
+Empty
 BundleRoundTrip(
@@ -2549,39 +2549,72 @@
 ) %7B%0A        
-TapPattern p1 =
+Bundle b = p.toBundle();%0A        assertEquals(p,
  new TapPatt
@@ -2621,40 +2621,119 @@
 ern(
+b)
 );%0A    
+%7D%0A%0A
     
-fillComplexPattern(p1
+public void testSingleTapBundleRoundTrip() %7B%0A        p.appendTap(TapPattern.DeviceSide.BACK, 10
 );%0A 
@@ -2751,17 +2751,16 @@
 le b = p
-1
 .toBundl
@@ -2786,17 +2786,16 @@
 Equals(p
-1
 , new Ta

Add new tests and simplify test structure a bit