<commit_before>package sword.langbook3.android.sdb;

import org.junit.Test;

import sword.collections.ImmutableIntSet;
import sword.database.MemoryDatabase;
import sword.langbook3.android.db.BunchesManager;
import sword.langbook3.android.db.LangbookDatabaseManager;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
import static sword.langbook3.android.db.AcceptationsManagerTest.addSimpleAcceptation;
import static sword.langbook3.android.sdb.AcceptationsSerializerTest.cloneBySerializing;
import static sword.langbook3.android.sdb.AcceptationsSerializerTest.findAcceptationsMatchingText;

/**
 * Include all test related to all values that a BunchesSerializer should serialize.
 *
 * Values the the AcceptationsSerializer should serialize are limited to:
 * <li>Bunches</li>
 */
public final class BunchesSerializerTest {

    @Test
    public void testSerializeBunchWithASingleSpanishAcceptation() {
        final MemoryDatabase inDb = new MemoryDatabase();
        final BunchesManager inManager = new LangbookDatabaseManager(inDb);

        final String languageCode = "es";
        final int inAlphabet = inManager.addLanguage(languageCode).mainAlphabet;

        final int inConcept = inManager.getMaxConcept() + 1;
        final String text = "cantar";
        final int acceptation = addSimpleAcceptation(inManager, inAlphabet, inConcept, text);

        final int bunch = inManager.getMaxConcept() + 1;
        final String bunchText = "verbo de primera conjugación";
        addSimpleAcceptation(inManager, inAlphabet, bunch, bunchText);
        assertTrue(inManager.addAcceptationInBunch(bunch, acceptation));

        final MemoryDatabase outDb = cloneBySerializing(inDb);
        final BunchesManager outManager = new LangbookDatabaseManager(outDb);

        final ImmutableIntSet outAcceptations = findAcceptationsMatchingText(outDb, text);
        assertEquals(1, outAcceptations.size());
        final int outAcceptation = outAcceptations.valueAt(0);

        final ImmutableIntSet outBunchAcceptations = findAcceptationsMatchingText(outDb, bunchText);
        assertEquals(1, outBunchAcceptations.size());
        final int outBunchAcceptation = outBunchAcceptations.valueAt(0);
        assertNotEquals(outBunchAcceptation, outAcceptation);

        final ImmutableIntSet acceptationsInBunch = outManager.getAcceptationsInBunch(outManager.conceptFromAcceptation(outBunchAcceptation));
        assertEquals(1, acceptationsInBunch.size());
        assertEquals(outAcceptation, acceptationsInBunch.valueAt(0));
    }
}
<commit_msg>Include test for serialization of multiple acceptations in bunch<commit_after>package sword.langbook3.android.sdb;

import org.junit.Test;

import sword.collections.ImmutableIntSet;
import sword.database.MemoryDatabase;
import sword.langbook3.android.db.BunchesManager;
import sword.langbook3.android.db.LangbookDatabaseManager;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
import static sword.langbook3.android.db.AcceptationsManagerTest.addSimpleAcceptation;
import static sword.langbook3.android.sdb.AcceptationsSerializerTest.cloneBySerializing;
import static sword.langbook3.android.sdb.AcceptationsSerializerTest.findAcceptationsMatchingText;

/**
 * Include all test related to all values that a BunchesSerializer should serialize.
 *
 * Values the the AcceptationsSerializer should serialize are limited to:
 * <li>Bunches</li>
 */
public final class BunchesSerializerTest {

    @Test
    public void testSerializeBunchWithASingleSpanishAcceptation() {
        final MemoryDatabase inDb = new MemoryDatabase();
        final BunchesManager inManager = new LangbookDatabaseManager(inDb);

        final String languageCode = "es";
        final int inAlphabet = inManager.addLanguage(languageCode).mainAlphabet;

        final int inConcept = inManager.getMaxConcept() + 1;
        final String text = "cantar";
        final int acceptation = addSimpleAcceptation(inManager, inAlphabet, inConcept, text);

        final int bunch = inManager.getMaxConcept() + 1;
        final String bunchText = "verbo de primera conjugación";
        addSimpleAcceptation(inManager, inAlphabet, bunch, bunchText);
        assertTrue(inManager.addAcceptationInBunch(bunch, acceptation));

        final MemoryDatabase outDb = cloneBySerializing(inDb);
        final BunchesManager outManager = new LangbookDatabaseManager(outDb);

        final ImmutableIntSet outAcceptations = findAcceptationsMatchingText(outDb, text);
        assertEquals(1, outAcceptations.size());
        final int outAcceptation = outAcceptations.valueAt(0);

        final ImmutableIntSet outBunchAcceptations = findAcceptationsMatchingText(outDb, bunchText);
        assertEquals(1, outBunchAcceptations.size());
        final int outBunchAcceptation = outBunchAcceptations.valueAt(0);
        assertNotEquals(outBunchAcceptation, outAcceptation);

        final ImmutableIntSet acceptationsInBunch = outManager.getAcceptationsInBunch(outManager.conceptFromAcceptation(outBunchAcceptation));
        assertEquals(1, acceptationsInBunch.size());
        assertEquals(outAcceptation, acceptationsInBunch.valueAt(0));

        assertTrue(outManager.getAcceptationsInBunch(outManager.conceptFromAcceptation(outAcceptation)).isEmpty());
    }

    @Test
    public void testSerializeBunchWithMultipleSpanishAcceptations() {
        final MemoryDatabase inDb = new MemoryDatabase();
        final BunchesManager inManager = new LangbookDatabaseManager(inDb);

        final String languageCode = "es";
        final int inAlphabet = inManager.addLanguage(languageCode).mainAlphabet;

        final int inSingConcept = inManager.getMaxConcept() + 1;
        final String singText = "cantar";
        final int inSingAcceptation = addSimpleAcceptation(inManager, inAlphabet, inSingConcept, singText);

        final int inDrinkConcept = inManager.getMaxConcept() + 1;
        final String drinkText = "beber";
        final int inDrinkAcceptation = addSimpleAcceptation(inManager, inAlphabet, inDrinkConcept, drinkText);

        final int bunch = inManager.getMaxConcept() + 1;
        final String bunchText = "verbo de primera conjugación";
        addSimpleAcceptation(inManager, inAlphabet, bunch, bunchText);
        assertTrue(inManager.addAcceptationInBunch(bunch, inSingAcceptation));
        assertTrue(inManager.addAcceptationInBunch(bunch, inDrinkAcceptation));

        final MemoryDatabase outDb = cloneBySerializing(inDb);
        final BunchesManager outManager = new LangbookDatabaseManager(outDb);

        final ImmutableIntSet outSingAcceptations = findAcceptationsMatchingText(outDb, singText);
        assertEquals(1, outSingAcceptations.size());
        final int outSingAcceptation = outSingAcceptations.valueAt(0);

        final ImmutableIntSet outDrinkAcceptations = findAcceptationsMatchingText(outDb, drinkText);
        assertEquals(1, outDrinkAcceptations.size());
        final int outDrinkAcceptation = outDrinkAcceptations.valueAt(0);
        assertNotEquals(outDrinkAcceptation, outSingAcceptation);

        final ImmutableIntSet outBunchAcceptations = findAcceptationsMatchingText(outDb, bunchText);
        assertEquals(1, outBunchAcceptations.size());
        final int outBunchAcceptation = outBunchAcceptations.valueAt(0);
        assertNotEquals(outBunchAcceptation, outSingAcceptation);
        assertNotEquals(outBunchAcceptation, outDrinkAcceptation);

        final ImmutableIntSet acceptationsInBunch = outManager.getAcceptationsInBunch(outManager.conceptFromAcceptation(outBunchAcceptation));
        assertEquals(2, acceptationsInBunch.size());
        assertTrue(acceptationsInBunch.contains(outSingAcceptation));
        assertTrue(acceptationsInBunch.contains(outDrinkAcceptation));

        assertTrue(outManager.getAcceptationsInBunch(outManager.conceptFromAcceptation(outSingAcceptation)).isEmpty());
        assertTrue(outManager.getAcceptationsInBunch(outManager.conceptFromAcceptation(outDrinkAcceptation)).isEmpty());
    }
}

{'fraction_non_alphanumeric': 0.07720543252171785, 'fraction_numerical': 0.0046494555242872875, 'mean_word_length': 4.79305457122608, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '2016896', 'n_tokens_mistral': 2199, 'n_tokens_neox': 2178, 'n_words': 447}