/*
 * LOGICAL-PARADOX.ORG
 * Copyright (C)2005 satoshi akabane(akabane@logical-paradox.org)
 * $Id: LocationTest.java,v 1.1 2005/05/31 14:38:20 rampil Exp $
 */
package org.logical_paradox.koike.core.search;

import junit.framework.TestCase;

/**
 * 索引語の位置情報クラスのテスト
 * @author satoshi akabane@logical-paradox.org
 * @version $Revision: 1.1 $
 */
public class LocationTest extends TestCase {

	/**
	 * Constructor for LocationTest.
	 * @param arg0
	 */
	public LocationTest(String arg0) {
		super(arg0);
	}
	/**
	 * equals()でtrueとなる場合のテスト
	 */
	public void testEquals() {
		Location a = new Location("ABCDEFG-xxxdddyyyz", 321, 900);
		Location b = new Location("ABCDEFG-xxxdddyyyz", 321, 900);

		assertEquals(a,b);
	}
	/**
	 * equals()でfalseとなる場合のテスト
	 *
	 */
	public void testNotEquals() {
		Location a = new Location("ABCDEFG-xxxdddyyyz", 321, 900);
		Location b = new Location("ABCDEFG-xxdddyyyz", 321, 900);

		assertFalse(a.equals(b));

		b = new Location("ABCDEFG-xxxdddyyyz", 320, 900);
		assertFalse(a.equals(b));

		b = new Location("ABCDEFG-xxxdddyyyz", 321, 920);
		assertFalse(a.equals(b));

		b = null;
		assertFalse(a.equals(b));
	}
	/**
	 * hashcodeが同じになる場合のテスト
	 */
	public void testHashCodeEquals() {
		Location a = new Location("ABCDEFG-xxxdddyyyz", 321, 900);
		Location b = new Location("ABCDEFG-xxxdddyyyz", 321, 900);

		assertEquals(a.hashCode(),b.hashCode());
	}
	/**
	 * hashcodeが違う値になる場合のテスト
	 */
	public void testHashCodeNotEquals() {
		Location a = new Location("ABCDEFG-xxxdddyyyz", 321, 900);
		Location b = new Location("ABCDEFG-xxdddyyyz", 321, 900);

		assertFalse(a.hashCode() == b.hashCode());
	}
	/**
	 * equals()とhashOode()の相互関係についてのテスト
	 * equals()が同じであれば、hashCode()も同じである必要がある
	 */
	public void testEqualsAndHashCodeRelation() {
		Location a = new Location("ABCDEFG-xxxdddyyyz", 321, 900);
		Location b = new Location("ABCDEFG-xxxdddyyyz", 321, 900);

		assertTrue(a.equals(b) && a.hashCode() == b.hashCode());
	}
	/**
	 * clone()の完全性に関するテスト
	 */	
	public void testClone() throws CloneNotSupportedException {
		Location a = new Location("ABCDEFG-xxxdddyyyz", 321, 900);
		Location b = (Location)a.clone();

		assertEquals(a.getNodeId(), b.getNodeId());
		assertEquals(a.getDocno(), b.getDocno());
		assertEquals(a.getOffset(), b.getOffset());
		assertTrue(a.equals(b) && a.hashCode() == b.hashCode());
	}
}
