test_helpers.py 2.19 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Jan 28 19:35:04 2020

@author: luna
"""

import unittest
from helpers import ParticleBinSorter
import sys
sys.path.append("C://Users//xbrjos//Desktop//Python")
import gepard
from gepard.analysis.particleAndMeasurement import Particle

class TestBinSorter(unittest.TestCase):
    def setUp(self):
        self.sorter = ParticleBinSorter()
        self.bins = self.sorter.bins
        
    def test_sort_particles_into_bins(self):
        particleList = []
        for upperBinLimit in self.bins:
            newParticle = Particle()
            newParticle.longSize = newParticle.shortSize = upperBinLimit - 1
            particleList.append(newParticle)
        lastParticle = Particle()
        lastParticle.longSize = lastParticle.shortSize = upperBinLimit + 1
        particleList.append(lastParticle)
        
        particlesInBins = self.sorter.sort_particles_into_bins(particleList)
        self.assertEqual(len(particlesInBins), len(self.bins)+1)
        for binContent in particlesInBins:
            self.assertEqual(len(binContent), 1)
            
    def test_get_empty_bins(self):
        emptyBins = self.sorter._get_empty_bins()
        self.assertEqual(len(emptyBins), len(self.bins)+1)
            
    def test_get_binIndex_of_particle(self):
        particle = Particle()
        particle.longSize = particle.shortSize = 0
        binIndex = self.sorter._get_binIndex_of_particle(particle)
        self.assertEqual(binIndex, 0)
        
        particle.longSize = particle.shortSize = 5
        binIndex = self.sorter._get_binIndex_of_particle(particle)
        self.assertEqual(binIndex, 0)
        
        particle.longSize = particle.shortSize = 5.01
        binIndex = self.sorter._get_binIndex_of_particle(particle)
        self.assertEqual(binIndex, 1)
        
        particle.longSize = particle.shortSize = 100
        binIndex = self.sorter._get_binIndex_of_particle(particle)
        self.assertEqual(binIndex, 4)
        
        particle.longSize = particle.shortSize = 1000
        binIndex = self.sorter._get_binIndex_of_particle(particle)
        self.assertEqual(binIndex, 7)
    
    
if __name__ == '__main__':
    unittest.main()