<commit_before>package eu.project.ttc.test.func;

import static org.assertj.core.api.Assertions.assertThat;

import java.util.Collection;
import java.util.List;
import java.util.Set;

import org.assertj.core.api.AbstractAssert;
import org.assertj.core.api.AbstractIterableAssert;
import org.assertj.core.util.Lists;

import com.google.common.base.Joiner;
import com.google.common.base.Objects;
import com.google.common.collect.Sets;
import com.google.common.primitives.Ints;

import eu.project.ttc.models.Term;
import eu.project.ttc.models.TermIndex;
import eu.project.ttc.models.TermVariation;
import eu.project.ttc.models.VariationType;

public class TermIndexAssert extends AbstractAssert<TermIndexAssert, TermIndex> {

	protected TermIndexAssert(TermIndex actual) {
		super(actual, TermIndexAssert.class);
	}

	public TermIndexAssert containsVariation(String baseGroupingKey, VariationType type, String variantGroupingKey) {
		List<TermVariation> potentialVariations = Lists.newArrayList();
		Set<TermVariation> sameType = Sets.newHashSet();
		
		for(TermVariation tv:getVariations()) {
			if(tv.getBase().getGroupingKey().equals(baseGroupingKey)
					&& tv.getVariant().getGroupingKey().equals(variantGroupingKey)) {
				potentialVariations.add(tv);
				if(tv.getVariationType() == type)
					return this;
			}
			if(type == tv.getVariationType())
				sameType.add(tv);
		}
		potentialVariations.addAll(Sets.newHashSet(actual.getTermByGroupingKey(baseGroupingKey).getVariations(type)));
		potentialVariations.addAll(Sets.newHashSet(actual.getTermByGroupingKey(variantGroupingKey).getBases(type)));
		potentialVariations.addAll(Sets.newHashSet(actual.getTermByGroupingKey(baseGroupingKey).getVariations()));
		potentialVariations.addAll(Sets.newHashSet(actual.getTermByGroupingKey(variantGroupingKey).getBases()));
		potentialVariations.addAll(sameType);
		
		failWithMessage("No such variation <%s--%s--%s> found in term index. Closed variations: <%s>", 
				baseGroupingKey, type, variantGroupingKey,
				Joiner.on(", ").join(potentialVariations.subList(0, Ints.min(10, potentialVariations.size())))
				);
		return this;
	}
	
	public TermIndexAssert containsVariation(String baseGroupingKey, VariationType type, String variantGroupingKey, Object info) {
		List<TermVariation> potentialVariations = Lists.newArrayList();
		Set<TermVariation> sameType = Sets.newHashSet();
		for(TermVariation tv:getVariations()) {
			if(tv.getBase().getGroupingKey().equals(baseGroupingKey)
					&& tv.getVariant().getGroupingKey().equals(variantGroupingKey)) {
				potentialVariations.add(tv);
				if(tv.getVariationType() == type && Objects.equal(info, tv.getInfo()))
					return this;
			}
			if(type == tv.getVariationType())
				sameType.add(tv);
		}
		
		potentialVariations.addAll(Sets.newHashSet(actual.getTermByGroupingKey(baseGroupingKey).getVariations(type)));
		potentialVariations.addAll(Sets.newHashSet(actual.getTermByGroupingKey(variantGroupingKey).getBases(type)));
		potentialVariations.addAll(Sets.newHashSet(actual.getTermByGroupingKey(baseGroupingKey).getVariations()));
		potentialVariations.addAll(Sets.newHashSet(actual.getTermByGroupingKey(variantGroupingKey).getBases()));
		potentialVariations.addAll(sameType);
		
		failWithMessage("No such variation <%s--%s[%s]--%s> found in term index. Closed variations: <%s>", 
				baseGroupingKey, type, 
				info,
				variantGroupingKey,
				Joiner.on(", ").join(potentialVariations)
				);
		return this;
	}

<commit_msg>hasVariation* asserts fail when term gKey not found in term index <commit_after>package eu.project.ttc.test.func;

import static org.assertj.core.api.Assertions.assertThat;

import java.util.Collection;
import java.util.List;
import java.util.Set;

import org.assertj.core.api.AbstractAssert;
import org.assertj.core.api.AbstractIterableAssert;
import org.assertj.core.util.Lists;

import com.google.common.base.Joiner;
import com.google.common.base.Objects;
import com.google.common.collect.Sets;
import com.google.common.primitives.Ints;

import eu.project.ttc.models.Term;
import eu.project.ttc.models.TermIndex;
import eu.project.ttc.models.TermVariation;
import eu.project.ttc.models.VariationType;

public class TermIndexAssert extends AbstractAssert<TermIndexAssert, TermIndex> {

	protected TermIndexAssert(TermIndex actual) {
		super(actual, TermIndexAssert.class);
	}

	public TermIndexAssert containsVariation(String baseGroupingKey, VariationType type, String variantGroupingKey) {
		if(failToFindTerms(baseGroupingKey, variantGroupingKey))
			return this;
		
		
		List<TermVariation> potentialVariations = Lists.newArrayList();
		Set<TermVariation> sameType = Sets.newHashSet();
		
		for(TermVariation tv:getVariations()) {
			if(tv.getBase().getGroupingKey().equals(baseGroupingKey)
					&& tv.getVariant().getGroupingKey().equals(variantGroupingKey)) {
				potentialVariations.add(tv);
				if(tv.getVariationType() == type)
					return this;
			}
			if(type == tv.getVariationType())
				sameType.add(tv);
		}
		potentialVariations.addAll(Sets.newHashSet(actual.getTermByGroupingKey(baseGroupingKey).getVariations(type)));
		potentialVariations.addAll(Sets.newHashSet(actual.getTermByGroupingKey(variantGroupingKey).getBases(type)));
		potentialVariations.addAll(Sets.newHashSet(actual.getTermByGroupingKey(baseGroupingKey).getVariations()));
		potentialVariations.addAll(Sets.newHashSet(actual.getTermByGroupingKey(variantGroupingKey).getBases()));
		potentialVariations.addAll(sameType);
		
		failWithMessage("No such variation <%s--%s--%s> found in term index. Closed variations: <%s>", 
				baseGroupingKey, type, variantGroupingKey,
				Joiner.on(", ").join(potentialVariations.subList(0, Ints.min(10, potentialVariations.size())))
				);
		return this;
	}

	private boolean failToFindTerms(String... groupingKeys) {
		boolean failed = false;
		for(String gKey:groupingKeys) {
			if(actual.getTermByGroupingKey(gKey) == null) {
				failed = true;
				failWithMessage("Could not find term <%s> in termIndex", gKey);
			}
		}
		return failed;
	}
	
	public TermIndexAssert containsVariation(String baseGroupingKey, VariationType type, String variantGroupingKey, Object info) {
		if(failToFindTerms(baseGroupingKey, variantGroupingKey))
			return this;

		
		List<TermVariation> potentialVariations = Lists.newArrayList();
		Set<TermVariation> sameType = Sets.newHashSet();
		for(TermVariation tv:getVariations()) {
			if(tv.getBase().getGroupingKey().equals(baseGroupingKey)
					&& tv.getVariant().getGroupingKey().equals(variantGroupingKey)) {
				potentialVariations.add(tv);
				if(tv.getVariationType() == type && Objects.equal(info, tv.getInfo()))
					return this;
			}
			if(type == tv.getVariationType())
				sameType.add(tv);
		}
		
		potentialVariations.addAll(Sets.newHashSet(actual.getTermByGroupingKey(baseGroupingKey).getVariations(type)));
		potentialVariations.addAll(Sets.newHashSet(actual.getTermByGroupingKey(variantGroupingKey).getBases(type)));
		potentialVariations.addAll(Sets.newHashSet(actual.getTermByGroupingKey(baseGroupingKey).getVariations()));
		potentialVariations.addAll(Sets.newHashSet(actual.getTermByGroupingKey(variantGroupingKey).getBases()));
		potentialVariations.addAll(sameType);
		
		failWithMessage("No such variation <%s--%s[%s]--%s> found in term index. Closed variations: <%s>", 
				baseGroupingKey, type, 
				info,
				variantGroupingKey,
				Joiner.on(", ").join(potentialVariations)
				);
		return this;
	}


{'fraction_non_alphanumeric': 0.12496647894877984, 'fraction_numerical': 0.0008045052292839903, 'mean_word_length': 5.951537744641193, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 22, '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': '2650795', 'n_tokens_mistral': 2657, 'n_tokens_neox': 2372, 'n_words': 340}