<commit_before>package net.milosvasic.pussycat.android.filter

import net.milosvasic.pussycat.Messages
import net.milosvasic.pussycat.PussycatAbstract
import net.milosvasic.pussycat.android.TerminalPussycat
import net.milosvasic.pussycat.android.application.Application
import net.milosvasic.pussycat.application.APPLICATION_TYPE
import net.milosvasic.pussycat.application.PUSSYCAT_MODE
import net.milosvasic.pussycat.terminal.Printer
import net.milosvasic.pussycat.utils.Files
import org.junit.After
import org.junit.Assert
import org.junit.Before
import org.junit.Test
import java.io.File
import java.util.*
import java.util.concurrent.atomic.AtomicBoolean
import java.util.concurrent.atomic.AtomicInteger


class FilterTest {

    val linesPrinted = AtomicInteger()
    val testSets = HashMap<String, Int>()
    var resources = mutableListOf<String>()

    val printLineCallback = object : PrintLineCallback {
        override fun printLine(text: String?) {
            if (text != null) {
                if (!text.contains(Messages.NO_DATA_MATCHING_PARAMETERS) && !text.contains(TerminalPussycat.TERMINAL_CLEAR)) {
                    val got = linesPrinted.incrementAndGet()
                    println("[ $got ] >> $text")
                } else {
                    println(text)
                }
            } else {
                Assert.fail("We received null text!")
            }
        }
    }

    @Before
    fun beforeTestFilter() {
        testSets.put("nsnsjsjsj", 0)
        testSets.put("L ion", 0)
        testSets.put("Li on", 0)
        testSets.put("Lion", 3)
        testSets.put("Cow", 2)
        testSets.put("Elephant", 2)
        testSets.put("Lion || Elephant", 5)
        testSets.put("Elephant || Lion", 5)
        testSets.put("lion || elephant", 5)
        testSets.put("phant || Lion", 5)
        testSets.put("cow || zion", 3)
        testSets.put("cow && zion", 0)
        testSets.put("Lion && zion", 1)
        testSets.put("Zion && Lion", 1)
        testSets.put("Zion && zion", 1)
        testSets.put("vehicle", 2)
        testSets.put("animal", 4)
        testSets.put("animal && !lion", 2)

        resources.addAll(Files.getResourceFiles("samples/android/filter"))
        Assert.assertTrue(resources.size == 1)
        val root = PussycatAbstract.getPussycatHome()
        for (resource in resources) {
            val localSample = File(root.absolutePath, resource)
            if (!localSample.exists()) {
                val input = javaClass.classLoader.getResourceAsStream("samples/android/filter/$resource")
                localSample.writeBytes(input.readBytes())
                input.close()
            }
            if (!localSample.exists()) {
                println("Couldn't prepare test resource ${localSample.absolutePath}")
                Assert.fail()
            }<commit_msg>Pussycat:  Working on filter test: adding new filter cases.<commit_after>package net.milosvasic.pussycat.android.filter

import net.milosvasic.pussycat.Messages
import net.milosvasic.pussycat.PussycatAbstract
import net.milosvasic.pussycat.android.TerminalPussycat
import net.milosvasic.pussycat.android.application.Application
import net.milosvasic.pussycat.application.APPLICATION_TYPE
import net.milosvasic.pussycat.application.PUSSYCAT_MODE
import net.milosvasic.pussycat.terminal.Printer
import net.milosvasic.pussycat.utils.Files
import org.junit.After
import org.junit.Assert
import org.junit.Before
import org.junit.Test
import java.io.File
import java.util.*
import java.util.concurrent.atomic.AtomicBoolean
import java.util.concurrent.atomic.AtomicInteger


class FilterTest {

    val linesPrinted = AtomicInteger()
    val testSets = HashMap<String, Int>()
    var resources = mutableListOf<String>()

    val printLineCallback = object : PrintLineCallback {
        override fun printLine(text: String?) {
            if (text != null) {
                if (!text.contains(Messages.NO_DATA_MATCHING_PARAMETERS) && !text.contains(TerminalPussycat.TERMINAL_CLEAR)) {
                    val got = linesPrinted.incrementAndGet()
                    println("[ $got ] >> $text")
                } else {
                    println(text)
                }
            } else {
                Assert.fail("We received null text!")
            }
        }
    }

    @Before
    fun beforeTestFilter() {
        testSets.put("nsnsjsjsj", 0)
        testSets.put("L ion", 0)
        testSets.put("Li on", 0)
        testSets.put("Lion", 3)
        testSets.put("Cow", 2)
        testSets.put("Elephant", 2)
        testSets.put("Lion || Elephant", 5)
        testSets.put("Elephant || Lion", 5)
        testSets.put("lion || elephant", 5)
        testSets.put("phant || Lion", 5)
        testSets.put("cow || zion", 3)
        testSets.put("cow && zion", 0)
        testSets.put("Lion && zion", 1)
        testSets.put("Zion && Lion", 1)
        testSets.put("Zion && zion", 1)
        testSets.put("vehicle", 2)
        testSets.put("animal", 4)
        testSets.put("animal && !lion", 2)
        testSets.put("!cow && !lion", 7)
        testSets.put("king || animal && !lion", 4)

        resources.addAll(Files.getResourceFiles("samples/android/filter"))
        Assert.assertTrue(resources.size == 1)
        val root = PussycatAbstract.getPussycatHome()
        for (resource in resources) {
            val localSample = File(root.absolutePath, resource)
            if (!localSample.exists()) {
                val input = javaClass.classLoader.getResourceAsStream("samples/android/filter/$resource")
                localSample.writeBytes(input.readBytes())
                input.close()
            }
            if (!localSample.exists()) {
                println("Couldn't prepare test resource ${localSample.absolutePath}")
                Assert.fail()
            }
{'fraction_non_alphanumeric': 0.1209732693625771, 'fraction_numerical': 0.006854009595613434, 'mean_word_length': 2.4723378941106486, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, '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': '421204', 'n_tokens_mistral': 1805, 'n_tokens_neox': 1706, 'n_words': 321}