<commit_before>#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import unittest

from hwt.hdl.constants import Time
from hwt.interfaces.std import FifoReader, FifoWriter
from hwt.interfaces.utils import addClkRstn
from hwt.simulator.simTestCase import SimTestCase
from hwt.synthesizer.unit import Unit
from hwtLib.mem.fifo import Fifo


class FifoReaderPassTrought(Unit):
    def _declr(self):
        addClkRstn(self)
        self.din = FifoReader()
        self.dout = FifoReader()

    def _impl(self):
        self.dout(self.din)


class FifoWriterPassTrought(FifoReaderPassTrought):
    def _declr(self):
        addClkRstn(self)
        self.din = FifoWriter()
        self.dout = FifoWriter()


class FifoAgentsTC(SimTestCase):
    def test_fifoReader(self):
        u = FifoReaderPassTrought()

        self.prepareUnit(u)
        self.randomize(u.din)
        self.randomize(u.dout)

        ref = [i for i in range(30)]
        u.din._ag.data.extend(ref)
        self.runSim(120 * 10 * Time.ns)

        self.assertValSequenceEqual(u.dout._ag.data, ref)

    def test_fifoWriter(self):
        u = FifoWriterPassTrought()

        self.prepareUnit(u)
        self.randomize(u.din)
        self.randomize(u.dout)

        ref = [i for i in range(30)]
        u.din._ag.data.extend(ref)
        self.runSim(120 * 10 * Time.ns)

        self.assertValSequenceEqual(u.dout._ag.data, ref)


class FifoTC(SimTestCase):
    def setUp(self):
        u = self.u = Fifo()
        u.DATA_WIDTH.set(8)
        u.DEPTH.set(4)
        u.EXPORT_SIZE.set(True)
        self.prepareUnit(u)

    def getTime(self, wordCnt):
        return wordCnt * 10 * Time.ns

    def test_fifoSingleWord(self):
        u = self.u

        expected = [1]
        u.dataIn._ag.data.extend(expected)

        self.runSim(90 * Time.ns)

        collected = u.dataOut._ag.data

        self.assertValSequenceEqual(collected, expected)

    def test_fifoWritterDisable(self):
        u = self.u

        data = [1, 2, 3, 4]
        u.dataIn._ag.data.extend(data)
        u.dataIn._ag._enabled = False

        self.runSim(self.getTime(8))

        self.assertValSequenceEqual(u.dataOut._ag.data, [])
        self.assertValSequenceEqual(u.dataIn._ag.data, data)
<commit_msg>grammar fix<commit_after>#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import unittest

from hwt.hdl.constants import Time
from hwt.interfaces.std import FifoReader, FifoWriter
from hwt.interfaces.utils import addClkRstn
from hwt.simulator.simTestCase import SimTestCase
from hwt.synthesizer.unit import Unit
from hwtLib.mem.fifo import Fifo


class FifoReaderPassTrought(Unit):
    def _declr(self):
        addClkRstn(self)
        self.din = FifoReader()
        self.dout = FifoReader()

    def _impl(self):
        self.dout(self.din)


class FifoWriterPassTrought(FifoReaderPassTrought):
    def _declr(self):
        addClkRstn(self)
        self.din = FifoWriter()
        self.dout = FifoWriter()


class FifoAgentsTC(SimTestCase):
    def test_fifoReader(self):
        u = FifoReaderPassTrought()

        self.prepareUnit(u)
        self.randomize(u.din)
        self.randomize(u.dout)

        ref = [i for i in range(30)]
        u.din._ag.data.extend(ref)
        self.runSim(120 * 10 * Time.ns)

        self.assertValSequenceEqual(u.dout._ag.data, ref)

    def test_fifoWriter(self):
        u = FifoWriterPassTrought()

        self.prepareUnit(u)
        self.randomize(u.din)
        self.randomize(u.dout)

        ref = [i for i in range(30)]
        u.din._ag.data.extend(ref)
        self.runSim(120 * 10 * Time.ns)

        self.assertValSequenceEqual(u.dout._ag.data, ref)


class FifoTC(SimTestCase):
    def setUp(self):
        u = self.u = Fifo()
        u.DATA_WIDTH.set(8)
        u.DEPTH.set(4)
        u.EXPORT_SIZE.set(True)
        self.prepareUnit(u)

    def getTime(self, wordCnt):
        return wordCnt * 10 * Time.ns

    def test_fifoSingleWord(self):
        u = self.u

        expected = [1]
        u.dataIn._ag.data.extend(expected)

        self.runSim(90 * Time.ns)

        collected = u.dataOut._ag.data

        self.assertValSequenceEqual(collected, expected)

    def test_fifoWriterDisable(self):
        u = self.u

        data = [1, 2, 3, 4]
        u.dataIn._ag.data.extend(data)
        u.dataIn._ag._enabled = False

        self.runSim(self.getTime(8))

        self.assertValSequenceEqual(u.dataOut._ag.data, [])
        self.assertValSequenceEqual(u.dataIn._ag.data, data)

{'fraction_non_alphanumeric': 0.11455315355471361, 'fraction_numerical': 0.0124804992199688, 'mean_word_length': 2.394856278366112, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '202250', 'n_tokens_mistral': 1662, 'n_tokens_neox': 1565, 'n_words': 279}