<commit_before>package com.peterphi.std.guice.hibernate.webquery.impl.functions;

import com.peterphi.std.guice.hibernate.webquery.impl.QProperty;
import com.peterphi.std.guice.hibernate.webquery.impl.QPropertyRef;
import org.hibernate.criterion.Criterion;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class BetweenTest
{
	@Test
	public void testBinaryRange()
	{
		final QProperty prop = new QProperty(null, null, "x", Integer.class, false);
		final QPropertyRef ref = new QPropertyRef(null, prop);

		final Criterion criterion = new Between(ref, "1..2").encode();

		assertEquals("x between 1 and 2", criterion.toString());
	}


	@Test
	public void testLeftOnlyRange()<commit_msg>Add a unit test for Between applied to a size field (note: the assertEquals expected value looks wrong due to Hibernate bug https://hibernate.atlassian.net/browse/HHH-9869 - see a potential fix PR at https://github.com/hibernate/hibernate-orm/pull/980)<commit_after>package com.peterphi.std.guice.hibernate.webquery.impl.functions;

import com.peterphi.std.guice.hibernate.webquery.impl.QProperty;
import com.peterphi.std.guice.hibernate.webquery.impl.QPropertyRef;
import com.peterphi.std.guice.hibernate.webquery.impl.QRelation;
import com.peterphi.std.guice.hibernate.webquery.impl.QSizeProperty;
import org.hibernate.criterion.Criterion;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class BetweenTest
{
	@Test
	public void testBinaryRange()
	{
		final QProperty prop = new QProperty(null, null, "x", Integer.class, false);
		final QPropertyRef ref = new QPropertyRef(null, prop);

		final Criterion criterion = new Between(ref, "1..2").encode();

		assertEquals("x between 1 and 2", criterion.toString());
	}


	@Test
	public void testBinarySizeRange()
	{
		final QRelation relation = new QRelation(null, null, "children", null, false);
		final QSizeProperty prop = new QSizeProperty(relation);
		final QPropertyRef ref = new QPropertyRef(null, prop);

		final Criterion criterion = new Between(ref, "1..2").encode();

		// N.B. the toString of size restrictions is incorrect due to HHH-9869 so this looks wrong
		assertEquals("children.size<=1 and children.size>=2", criterion.toString());
	}


	@Test
	public void testLeftOnlyRange()
{'fraction_non_alphanumeric': 0.11427320490367776, 'fraction_numerical': 0.010070052539404553, 'mean_word_length': 5.109625668449198, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, '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': '6546706', 'n_tokens_mistral': 771, 'n_tokens_neox': 696, 'n_words': 183}