<s> """<STR_LIT>""" <EOL> import unittest <EOL> import random <EOL> import tempfile <EOL> import shutil <EOL> import os <EOL> from CGAT . NCL import * <EOL> class TestNCLSimpleNegativeIntervals ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . mIndex = NCLSimple <EOL> def testBuild1 ( self ) : <EOL> index = self . mIndex ( ) <EOL> self . assertRaises ( ValueError , index . add , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> def testBuild2 ( self ) : <EOL> index = self . mIndex ( ) <EOL> self . assertRaises ( ValueError , index . add , - <NUM_LIT:10> , <NUM_LIT:0> ) <EOL> class TestNCLSimple ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . l = [ ( <NUM_LIT:10> , <NUM_LIT:20> , <NUM_LIT:0> ) , <EOL> ( <NUM_LIT:15> , <NUM_LIT> , <NUM_LIT:1> ) , <EOL> ( <NUM_LIT:30> , <NUM_LIT:50> , <NUM_LIT:2> ) , <EOL> ] <EOL> self . tests = ( ( ( <NUM_LIT:10> , <NUM_LIT:15> ) , ( <NUM_LIT:0> , ) ) , <EOL> ( ( <NUM_LIT:10> , <NUM_LIT:30> ) , ( <NUM_LIT:0> , <NUM_LIT:1> ) ) , <EOL> ( ( <NUM_LIT:0> , <NUM_LIT:10> ) , ( ) , ) , <EOL> ( ( <NUM_LIT:10> , <NUM_LIT:50> ) , ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> ) , ) , <EOL> ( ( <NUM_LIT> , <NUM_LIT:30> ) , ( ) ) , <EOL> ) <EOL> self . mIndex = NCLSimple <EOL> def checkIntervals ( self , index ) : <EOL> for a , b in self . tests : <EOL> result = tuple ( sorted ( [ x [ <NUM_LIT:2> ] for x in index . find ( a [ <NUM_LIT:0> ] , a [ <NUM_LIT:1> ] ) ] ) ) <EOL> self . assertEqual ( result , b ) <EOL> def buildIndex ( self , l ) : <EOL> index = self . mIndex ( ) <EOL> for start , end , value in self . l : <EOL> index . add ( start , end ) <EOL> return index <EOL> def testBuild ( self ) : <EOL> index = self . buildIndex ( self . l ) <EOL> self . assertRaises ( ValueError , index . add , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> def testSortedList ( self ) : <EOL> """<STR_LIT>""" <EOL> l = self . l [ : ] <EOL> l . sort ( ) <EOL> self . checkIntervals ( self . buildIndex ( l ) ) <EOL> def testReverseList ( self ) : <EOL> """<STR_LIT>""" <EOL> l = self . l [ : ] <EOL> l . sort ( ) <EOL> l . reverse ( ) <EOL> self . checkIntervals ( self . buildIndex ( l ) ) <EOL> def testRandomizedList ( self ) : <EOL> """<STR_LIT>""" <EOL> l = self . l [ : ] <EOL> random . shuffle ( l ) <EOL> self . checkIntervals ( self . buildIndex ( l ) ) <EOL> def testPointIntervals ( self ) : <EOL> bits = [ <NUM_LIT:0> ] * <NUM_LIT:100> <EOL> for start , end , val in self . l : <EOL> bits [ start : end ] = [ <NUM_LIT:1> ] * ( end - start ) <EOL> index = self . buildIndex ( self . l ) <EOL> for x in xrange ( <NUM_LIT:0> , len ( bits ) ) : <EOL> r = len ( list ( index . find ( x , x + <NUM_LIT:1> ) ) ) <EOL> self . assertEqual ( <EOL> r > <NUM_LIT:0> , bits [ x ] , "<STR_LIT>" % ( x , bits [ x ] , r ) ) <EOL> def testEmptyIntervals ( self ) : <EOL> bits = [ <NUM_LIT:0> ] * <NUM_LIT:100> <EOL> index = self . buildIndex ( self . l ) <EOL> for x in xrange ( <NUM_LIT:0> , len ( bits ) ) : <EOL> self . assertRaises ( IndexError , index . find , x , x ) <EOL> class TestNCL ( TestNCLSimple ) : <EOL> def setUp ( self ) : <EOL> TestNCLSimple . setUp ( self ) <EOL> self . mIndex = NCL <EOL> def buildIndex ( self , l ) : <EOL> index = self . mIndex ( ) <EOL> for start , end , value in self . l : <EOL> index . add ( start , end , value ) <EOL> return index <EOL> def testBuild ( self ) : <EOL> index = self . buildIndex ( self . l ) <EOL> self . assertRaises ( ValueError , index . add , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:4> ) <EOL> class TestNCLDisk ( TestNCLSimple ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> TestNCLSimple . setUp ( self ) <EOL> self . mIndex = NCL <EOL> self . tmpdir = tempfile . mkdtemp ( ) <EOL> self . tmpfile = os . path . join ( self . tmpdir , "<STR_LIT>" ) <EOL> def buildIndex ( self , l ) : <EOL> index = self . mIndex ( filestem = self . tmpfile ) <EOL> for start , end , value in self . l : <EOL> index . add ( start , end , value ) <EOL> del index <EOL> index = self . mIndex ( filestem = self . tmpfile ) <EOL> return index <EOL> def testBuild ( self ) : <EOL> index = self . buildIndex ( self . l ) <EOL> self . assertRaises ( ValueError , index . add , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:4> ) <EOL> def tearDown ( self ) : <EOL> shutil . rmtree ( self . tmpdir ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
