<commit_before>import openvoronoi as ovd

import time
import math
import sys
import pickle
import gzip

if __name__ == "__main__":  
    Nmax  = int(sys.argv[1])
    vd = ovd.VoronoiDiagram(1,120)
    print "random_linesegments.py:  ",Nmax," random segments."
    sys.stdout.flush()
    filename = "../src/test/data/randomsegments_{0}.pickle.gz".format(Nmax) #  load pre-computed segments 
    # (produced with lineseg_dataset_generator.py)
    f = gzip.open(filename, 'rb')
    pstring = f.read()
    segs = pickle.loads( pstring )
    f.close()

    id_list = []
    for seg in segs:
        seg_id=[]
        seg_id.append( vd.addVertexSite( seg[0] ) )
        seg_id.append( vd.addVertexSite( seg[1] ) )
        id_list.append( seg_id )
    print "all point-sites inserted."
    assert( vd.check() )
    nsegs = Nmax
    for s in id_list:
        vd.addLineSite(s[0],s[1])
    print "all line-sites inserted."
    c = vd.check()
    print " VD check: ", c
    if c:
        exit(0)
    else:
        exit(-1)
    

<commit_msg>make this test run stand-alone also. look in two different places for the input data, since we may run this from the build-directory, or from the test-directory.<commit_after>import openvoronoi as ovd

import time
import math
import sys
import pickle
import gzip
import os

def test(Nmax):
    vd = ovd.VoronoiDiagram(1,120)
    print "random_linesegments.py:  ",Nmax," random segments."
    sys.stdout.flush()
    f1 = "../src/test/data/randomsegments_{0}.pickle.gz".format(Nmax)
    f2 = "data/randomsegments_{0}.pickle.gz".format(Nmax)
    filename = ""
    if os.path.exists( f1 ):
        filename = f1 # "../src/test/data/randomsegments_{0}.pickle.gz".format(Nmax) #  load pre-computed segments 
    elif os.path.exists( f2 ):
        filename = f2
    # (produced with lineseg_dataset_generator.py)
    f = gzip.open(filename, 'rb')
    pstring = f.read()
    segs = pickle.loads( pstring )
    f.close()

    id_list = []
    for seg in segs:
        seg_id=[]
        seg_id.append( vd.addVertexSite( seg[0] ) )
        seg_id.append( vd.addVertexSite( seg[1] ) )
        id_list.append( seg_id )
    print "all point-sites inserted."
    assert( vd.check() )
    nsegs = Nmax
    for s in id_list:
        vd.addLineSite(s[0],s[1])
    print "all line-sites inserted."
    c = vd.check()
    print " VD check: ", c
    print sys.version
    print ovd.version()
    if c:
        print "Test passed."
        #exit(0)
    else:
        print "Test failed."
        #exit(-1)
    print "end of test()"
    
if __name__ == "__main__":  
    Nmax = 128 
    if len(sys.argv) == 2:
        Nmax  = int(sys.argv[1])
    test(Nmax)
    print "end of script"


{'fraction_non_alphanumeric': 0.13033791310805792, 'fraction_numerical': 0.013367991088005942, 'mean_word_length': 2.4494238156209986, 'pattern_counts': {'":': 2, '<': 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': '6937006', 'n_tokens_mistral': 993, 'n_tokens_neox': 971, 'n_words': 240}