/*
 * SimMetrics - SimMetrics is a java library of Similarity or Distance Metrics,
 * e.g. Levenshtein Distance, that provide float based similarity measures
 * between String Data. All metrics return consistent measures rather than
 * unbounded similarity scores.
 * 
 * Copyright (C) 2014 SimMetrics authors
 * 
 * This file is part of SimMetrics. This program is free software: you can
 * redistribute it and/or modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * SimMetrics. If not, see <http://www.gnu.org/licenses/>.
 */
package org.simmetrics.metrics;

import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;

import java.util.List;

import org.junit.Test;
import org.simmetrics.Distance;
import org.simmetrics.DistanceTest;

@SuppressWarnings("javadoc")
public final class HammingDistanceTest {

	public final static class DistanceListTest extends
			DistanceTest<List<String>> {

		@Override
		protected Distance<List<String>> getMetric() {
			return HammingDistance.forList();
		}

		@Override
		protected boolean satisfiesSubadditivity() {
			return false;
		}

		@Override
		protected List<String> getEmpty() {
			return emptyList();
		}

		@SuppressWarnings("unchecked")
		@Override
		protected DistanceTest.T<List<String>>[] getTests() {
			return new T[] {
					new T<>(0.0000f, asList("test", "string1"), asList("test",
							"string1")),
					new T<>(1.0000f, asList("test", "string1"), asList("test",
							"string2")),
					new T<>(1.0000f, asList("aaa", "bbb", "ccc", "ddd"),
							asList("aaa", "bbb", "ccc", "eee")),
					new T<>(1.0000f, asList("aaa", "bbb"), asList("aaa", "aaa")),
					new T<>(1.0000f, asList("a", "b", "c", "d"), asList("a",
							"b", "c", "e")),
					new T<>(2.0000f, asList("a", "b", "c", "d"), asList("a",
							"b", "e", "f")) };
		}

		@Test(expected = IllegalArgumentException.class)
		public void differentSize() {
			getMetric().distance(asList("test", "string1"), asList("test"));
		}

	}

	public final static class StringDistanceTest extends DistanceTest<String> {

		@Override
		protected Distance<String> getMetric() {
			return HammingDistance.forString();
		}

		@Override
		protected boolean satisfiesSubadditivity() {
			return false;
		}

		@Override
		protected String getEmpty() {
			return "";
		}

		@SuppressWarnings("unchecked")
		@Override
		protected DistanceTest.T<String>[] getTests() {
			return new T[] { new T<>(0.0000f, "test string1", "test string1"),
					new T<>(1.0000f, "test string1", "test string2"),
					new T<>(3.0000f, "aaabbb", "aaaaaa"),
					new T<>(1.0000f, "abcd", "abce"),
					new T<>(2.0000f, "abcd", "abef") };
		}

		@Test(expected = IllegalArgumentException.class)
		public void differentLength() {
			getMetric().distance("test", "test string2");
		}

	}

}

@@ -1530,94 +1530,8 @@
 %0D%0A%0D%0A
-%09%09@Override%0D%0A%09%09protected boolean satisfiesSubadditivity() %7B%0D%0A%09%09%09return false;%0D%0A%09%09%7D%0D%0A%0D%0A
 %09%09@O
@@ -1738,352 +1738,8 @@
  %7B%0D%0A
-%09%09%09%09%09new T%3C%3E(0.0000f, asList(%22test%22, %22string1%22), asList(%22test%22,%0D%0A%09%09%09%09%09%09%09%22string1%22)),%0D%0A%09%09%09%09%09new T%3C%3E(1.0000f, asList(%22test%22, %22string1%22), asList(%22test%22,%0D%0A%09%09%09%09%09%09%09%22string2%22)),%0D%0A%09%09%09%09%09new T%3C%3E(1.0000f, asList(%22aaa%22, %22bbb%22, %22ccc%22, %22ddd%22),%0D%0A%09%09%09%09%09%09%09asList(%22aaa%22, %22bbb%22, %22ccc%22, %22eee%22)),%0D%0A%09%09%09%09%09new T%3C%3E(1.0000f, asList(%22aaa%22, %22bbb%22), asList(%22aaa%22, %22aaa%22)),%0D%0A
 %09%09%09%09
@@ -2274,94 +2274,8 @@
 %0D%0A%0D%0A
-%09%09@Override%0D%0A%09%09protected boolean satisfiesSubadditivity() %7B%0D%0A%09%09%09return false;%0D%0A%09%09%7D%0D%0A%0D%0A
 %09%09@O
@@ -2471,38 +2471,32 @@
 (0.0000f, %22test 
-string
 1%22, %22test string
@@ -2489,22 +2489,16 @@
 , %22test 
-string
 1%22),%0D%0A%09%09
@@ -2523,22 +2523,16 @@
 , %22test 
-string
 1%22, %22tes
@@ -2533,22 +2533,16 @@
 , %22test 
-string
 2%22),%0D%0A%09%09
@@ -2614,16 +2614,18 @@
 abcd
+xy
 %22, %22abce
 %22),%0D
@@ -2620,16 +2620,18 @@
 %22, %22abce
+xy
 %22),%0D%0A%09%09%09
@@ -2658,16 +2658,18 @@
 abcd
+xy
 %22, %22abef
 %22) %7D
@@ -2664,16 +2664,18 @@
 %22, %22abef
+xy
 %22) %7D;%0D%0A%09

Hamming distance is subadditive