<commit_before>/*
 * Copyright (C) 2004-2005  exedio GmbH (www.exedio.com)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
package com.exedio.cope;

import java.util.Date;


public class AttributeDateTest extends AttributeTest
{

	public void testSomeDate() throws ConstraintViolationException
	{
		final Date date = new Date(1087365298214l);
		final Date nextDate = new Date(date.getTime()+1l);

		assertEquals(item.TYPE, item.someDate.getType());
		assertEquals(null, item.getSomeDate());
		assertContains(item, item2, item.TYPE.search(item.someDate.equal((Date)null)));
		assertContains(item, item2, item.TYPE.search(item.someDate.isNull()));
		assertContains(item.TYPE.search(item.someDate.notEqual((Date)null)));
		assertContains(item.TYPE.search(item.someDate.isNotNull()));

		item.setSomeDate(date);
		assertEquals(date, item.getSomeDate());

		assertContains(date, null, search(item.someDate));
		assertContains(date, search(item.someDate, item.someDate.equal(date)));

		restartTransaction();
		assertEquals(date, item.getSomeDate());
		assertEquals(list(item), item.TYPE.search(item.someDate.equal(date)));
		assertEquals(list(item2), item.TYPE.search(item.someDate.notEqual(date)));
		assertEquals(list(item2), item.TYPE.search(item.someDate.equal((Date)null)));
		assertEquals(list(item2), item.TYPE.search(item.someDate.isNull()));
		assertEquals(list(item), item.TYPE.search(item.someDate.notEqual((Date)null)));
		assertEquals(list(item), item.TYPE.search(item.someDate.isNotNull()));

		item.setSomeDate(nextDate);
		restartTransaction();
		assertEquals(nextDate, item.getSomeDate());

		item.setSomeDate(null);
		assertEquals(null, item.getSomeDate());
		
		restartTransaction();
		assertEquals(null, item.getSomeDate());
		
		final Date beforeTouch = new Date();
		item.touchSomeDate();
		final Date afterTouch = new Date();
		assertTrue(!beforeTouch.after(item.getSomeDate()));
		assertTrue(!afterTouch.before(item.getSomeDate()));

		try
		{
			item.set(item.someDate, new Integer(10));
			fail();
		}
		catch(ClassCastException e)
		{
			assertEquals("expected date, got " + Integer.class.getName() + " for someDate", e.getMessage());
		}
	}
	
	public void testSomeLongDate()
	{
		final Date date = new Date(1087368298214l);
		final Date nextDate = new Date(date.getTime()+1l);

		assertEquals(item.TYPE, item.someLongDate.getType());
		assertEquals(null, item.getSomeLongDate());
		assertContains(item, item2, item.TYPE.search(item.someLongDate.equal((Date)null)));
		assertContains(item, item2, item.TYPE.search(item.someLongDate.isNull()));
		assertContains(item.TYPE.search(item.someLongDate.notEqual((Date)null)));
		assertContains(item.TYPE.search(item.someLongDate.isNotNull()));

		item.setSomeLongDate(date);
		assertEquals(date, item.getSomeLongDate());

		restartTransaction();
		assertEquals(date, item.getSomeLongDate());
		assertEquals(list(item), item.TYPE.search(item.someLongDate.equal(date)));
		assertEquals(list(item2), item.TYPE.search(item.someLongDate.notEqual(date)));
		assertEquals(list(item2), item.TYPE.search(item.someLongDate.equal((Date)null)));
		assertEquals(list(item2), item.TYPE.search(item.someLongDate.isNull()));
		assertEquals(list(item), item.TYPE.search(item.someLongDate.notEqual((Date)null)));
		assertEquals(list(item), item.TYPE.search(item.someLongDate.isNotNull()));

		assertContains(date, null, search(item.someLongDate));
		assertContains(date, search(item.someLongDate, item.someLongDate.equal(date)));

		item.setSomeLongDate(nextDate);
		restartTransaction();
		assertEquals(nextDate, item.getSomeLongDate());

		item.setSomeLongDate(null);
		assertEquals(null, item.getSomeLongDate());
		
		restartTransaction();
		assertEquals(null, item.getSomeLongDate());
	}
	
	public static String toString(final Date date)
	{
		return date==null ? "NULL" : String.valueOf(date.getTime());
	}
	
	public static void assertEquals(final Date expectedDate, final Date actualDate)
	{
		assertEquals("ts: "+toString(expectedDate)+" "+toString(actualDate), (Object)expectedDate, (Object)actualDate);
	}

}<commit_msg>more tests for date milliseconds resolution<commit_after>/*
 * Copyright (C) 2004-2005  exedio GmbH (www.exedio.com)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
package com.exedio.cope;

import java.util.Date;


public class AttributeDateTest extends AttributeTest
{

	public void testSomeDate() throws ConstraintViolationException
	{
		final Date date = new Date(1087365298214l);
		final Date beforeDate = new Date(date.getTime()-1l);
		final Date nextDate = new Date(date.getTime()+1l);

		assertEquals(item.TYPE, item.someDate.getType());
		assertEquals(null, item.getSomeDate());
		assertContains(item, item2, item.TYPE.search(item.someDate.equal((Date)null)));
		assertContains(item, item2, item.TYPE.search(item.someDate.isNull()));
		assertContains(item.TYPE.search(item.someDate.notEqual((Date)null)));
		assertContains(item.TYPE.search(item.someDate.isNotNull()));

		item.setSomeDate(date);
		assertEquals(date, item.getSomeDate());

		assertContains(date, null, search(item.someDate));
		assertContains(date, search(item.someDate, item.someDate.equal(date)));

		restartTransaction();
		assertEquals(date, item.getSomeDate());
		assertEquals(list(item), item.TYPE.search(item.someDate.equal(date)));
		assertEquals(list(item), item.TYPE.search(item.someDate.greaterOrEqual(date).and(item.someDate.lessOrEqual(date))));
		assertEquals(list(item2), item.TYPE.search(item.someDate.notEqual(date)));
		assertEquals(list(item2), item.TYPE.search(item.someDate.equal((Date)null)));
		assertEquals(list(item2), item.TYPE.search(item.someDate.isNull()));
		assertEquals(list(item), item.TYPE.search(item.someDate.notEqual((Date)null)));
		assertEquals(list(item), item.TYPE.search(item.someDate.isNotNull()));
		assertEquals(list(), item.TYPE.search(item.someDate.equal(beforeDate)));
		assertEquals(list(), item.TYPE.search(item.someDate.equal(nextDate)));
		assertEquals(list(), item.TYPE.search(item.someDate.greaterOrEqual(beforeDate).and(item.someDate.lessOrEqual(beforeDate))));
		assertEquals(list(), item.TYPE.search(item.someDate.greaterOrEqual(nextDate).and(item.someDate.lessOrEqual(nextDate))));
		assertEquals(list(item), item.TYPE.search(item.someDate.greaterOrEqual(date).and(item.someDate.lessOrEqual(nextDate))));
		assertEquals(list(item), item.TYPE.search(item.someDate.greaterOrEqual(beforeDate).and(item.someDate.lessOrEqual(date))));

		item.setSomeDate(nextDate);
		restartTransaction();
		assertEquals(nextDate, item.getSomeDate());

		item.setSomeDate(null);
		assertEquals(null, item.getSomeDate());
		
		restartTransaction();
		assertEquals(null, item.getSomeDate());
		
		final Date beforeTouch = new Date();
		item.touchSomeDate();
		final Date afterTouch = new Date();
		assertTrue(!beforeTouch.after(item.getSomeDate()));
		assertTrue(!afterTouch.before(item.getSomeDate()));

		try
		{
			item.set(item.someDate, new Integer(10));
			fail();
		}
		catch(ClassCastException e)
		{
			assertEquals("expected date, got " + Integer.class.getName() + " for someDate", e.getMessage());
		}
	}
	
	public void testSomeLongDate()
	{
		final Date date = new Date(1087368298214l);
		final Date beforeDate = new Date(date.getTime()-1l);
		final Date nextDate = new Date(date.getTime()+1l);

		assertEquals(item.TYPE, item.someLongDate.getType());
		assertEquals(null, item.getSomeLongDate());
		assertContains(item, item2, item.TYPE.search(item.someLongDate.equal((Date)null)));
		assertContains(item, item2, item.TYPE.search(item.someLongDate.isNull()));
		assertContains(item.TYPE.search(item.someLongDate.notEqual((Date)null)));
		assertContains(item.TYPE.search(item.someLongDate.isNotNull()));

		item.setSomeLongDate(date);
		assertEquals(date, item.getSomeLongDate());

		restartTransaction();
		assertEquals(date, item.getSomeLongDate());
		assertEquals(list(item), item.TYPE.search(item.someLongDate.equal(date)));
		assertEquals(list(item), item.TYPE.search(item.someLongDate.greaterOrEqual(date).and(item.someLongDate.lessOrEqual(date))));
		assertEquals(list(item2), item.TYPE.search(item.someLongDate.notEqual(date)));
		assertEquals(list(item2), item.TYPE.search(item.someLongDate.equal((Date)null)));
		assertEquals(list(item2), item.TYPE.search(item.someLongDate.isNull()));
		assertEquals(list(item), item.TYPE.search(item.someLongDate.notEqual((Date)null)));
		assertEquals(list(item), item.TYPE.search(item.someLongDate.isNotNull()));
		assertEquals(list(), item.TYPE.search(item.someLongDate.equal(beforeDate)));
		assertEquals(list(), item.TYPE.search(item.someLongDate.equal(nextDate)));
		assertEquals(list(), item.TYPE.search(item.someLongDate.greaterOrEqual(beforeDate).and(item.someLongDate.lessOrEqual(beforeDate))));
		assertEquals(list(), item.TYPE.search(item.someLongDate.greaterOrEqual(nextDate).and(item.someLongDate.lessOrEqual(nextDate))));
		assertEquals(list(item), item.TYPE.search(item.someLongDate.greaterOrEqual(date).and(item.someLongDate.lessOrEqual(nextDate))));
		assertEquals(list(item), item.TYPE.search(item.someLongDate.greaterOrEqual(beforeDate).and(item.someLongDate.lessOrEqual(date))));

		assertContains(date, null, search(item.someLongDate));
		assertContains(date, search(item.someLongDate, item.someLongDate.equal(date)));

		item.setSomeLongDate(nextDate);
		restartTransaction();
		assertEquals(nextDate, item.getSomeLongDate());

		item.setSomeLongDate(null);
		assertEquals(null, item.getSomeLongDate());
		
		restartTransaction();
		assertEquals(null, item.getSomeLongDate());
	}
	
	public static String toString(final Date date)
	{
		return date==null ? "NULL" : String.valueOf(date.getTime());
	}
	
	public static void assertEquals(final Date expectedDate, final Date actualDate)
	{
		assertEquals("ts: "+toString(expectedDate)+" "+toString(actualDate), (Object)expectedDate, (Object)actualDate);
	}

}
{'fraction_non_alphanumeric': 0.14300941552673654, 'fraction_numerical': 0.011547344110854504, 'mean_word_length': 6.2358611825192805, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6534748', 'n_tokens_mistral': 3675, 'n_tokens_neox': 3386, 'n_words': 649}