<commit_before>/*
 * HUnifiedDataObjectTest.java
 * JUnit based test
 *
 * Created on 3. June 2007, 23:00
 */

package org.ujorm.criterion;

import java.util.ArrayList;
import java.util.List;
import org.ujorm.Key;
import org.ujorm.MyTestCase;
import org.ujorm.core.UjoComparator;
import static org.ujorm.criterion.Person.*;

/**
 * Criteria test
 * @author <NAME>
 */
public class UjoComparatorTest extends MyTestCase {

    Key<Person,Double> MOTHERS_CASH  = MOTHER.add(CASH);
    Key<Person,String> MOTHERS_NAME  = MOTHER.add(NAME);
    Key<Person,Double> GMOTHERS_CASH = MOTHER.add(MOTHER).add(CASH);

    private List<Person> persons;

    public UjoComparatorTest(String testName) {
        super(testName);
    }

    /** Create new Person */
    private Person createPerson(String name, Double cash) {
        Person result = new Person();
        result.set(NAME, name);
        result.set(CASH, cash);

        persons.add(result);
        return result;
    }

    @Override
    protected void setUp() throws Exception {
        persons = new ArrayList<Person>();

        Person p = createPerson("John" , 10.0);
        Person m = createPerson("Marry", 20.0);
        Person g = createPerson("Julia", 30.0);
        Person e = createPerson("Eva"  , 40.0);

        p.set(MOTHER, m);
        m.set(MOTHER, g);
        g.set(MOTHER, e);

    }

    @Override
    protected void tearDown() throws Exception {
        persons = null;
    }


    /** No sort for an empty Comparator */
    public void testInit_00() {
        List<Person> result = UjoComparator.<Person>of().sort(persons);
        assertEquals("John", result.get(0).get(NAME));
    }

    /** Sort by name */
    public void testInit_01() {
        List<Person> result = UjoComparator.<Person>of(NAME).sort(persons);
        assertEquals("Eva", result.get(0).get(NAME) );
    }

    /** Sort by mother's name */
    public void testInit_02() {
        CriteriaTool<Person> uc  = CriteriaTool.newInstance();
        UjoComparator comp = UjoComparator.of(MOTHERS_NAME);<commit_msg>CODE: A jUnit test cleaning<commit_after>/*
 * UjoComparatorTestTest.java
 * JUnit based test
 *
 * Created on 3. June 2007, 23:00
 */

package org.ujorm.criterion;

import java.util.ArrayList;
import java.util.List;
import org.ujorm.Key;
import org.ujorm.MyTestCase;
import org.ujorm.core.UjoComparator;
import static org.ujorm.criterion.Person.*;

/**
 * Criteria test
 * @author <NAME>
 */
public class UjoComparatorTest extends MyTestCase {

    final Key<Person,Double> MOTHERS_CASH  = MOTHER.add(CASH);
    final Key<Person,String> MOTHERS_NAME  = MOTHER.add(NAME);
    final Key<Person,Double> GMOTHERS_CASH = MOTHER.add(MOTHER).add(CASH);

    private List<Person> persons;

    public UjoComparatorTest(String testName) {
        super(testName);
    }

    /** Create new Person */
    private Person<Person> createPerson(String name, Double cash) {
        final Person<Person> result = new Person<Person>();
        result.set(NAME, name);
        result.set(CASH, cash);
        return result;
    }

    @Override
    protected void setUp() throws Exception {
        persons = new ArrayList<Person>();
        final Person<Person> p,m,g,e;

        persons.add(p = createPerson("John" , 10.0));
        persons.add(m = createPerson("Marry", 20.0));
        persons.add(g = createPerson("Julia", 30.0));
        persons.add(e = createPerson("Eva"  , 40.0));

        p.set(MOTHER, m);
        m.set(MOTHER, g);
        g.set(MOTHER, e);
    }

    @Override
    protected void tearDown() throws Exception {
        persons = null;
    }


    /** No sort for an empty Comparator */
    @SuppressWarnings("unchecked")
    public void testInit_00() {
        List<Person> result = UjoComparator.<Person>of().sort(persons);
        assertEquals("John", result.get(0).get(NAME));
    }

    /** Sort by name */
    @SuppressWarnings("unchecked")
    public void testInit_01() {
        List<Person> result = UjoComparator.<Person>of(NAME).sort(persons);
        assertEquals("Eva", result.get(0).get(NAME) );
    }

    /** Sort by mother's name */
    @SuppressWarnings("unchecked")
    public void testInit_02() {
        CriteriaTool<Person> uc  = CriteriaTool.newInstance();
        UjoComparator comp = UjoComparator.of(MOTHERS_NAME);
{'fraction_non_alphanumeric': 0.1334573355033713, 'fraction_numerical': 0.013485235991629853, 'mean_word_length': 2.907356948228883, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, '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': '5328048', 'n_tokens_mistral': 1422, 'n_tokens_neox': 1359, 'n_words': 304}