Example #1
0
def run(RUN_TRAIN, RUN_TEST, RUN_TRAIN2, RUN_TEST2, RUN_SAVE):
    tools.mkdir()
    if RUN_TRAIN : trainer()
    if RUN_TEST : tester()
    if RUN_TRAIN2 : trainer(type_=2)
    if RUN_TEST2 : tester(type_=2)
    if RUN_SAVE: tools.saver() 
Example #2
0
 def checkHW(self):
     plat = sys.platform.lower()	# try to detect the OS so that a device can be selected...
     print "checked platform"	
     if   plat[:5] == 'linux': opSys = "NIX"
     elif plat == 'win32': opSys = "WIN"
     else: opSys = "WIN"		
     tester(opSys,self.currentHW).test1(self.ui.textBrowser)
Example #3
0
def test(name, min_size, scale_factor, min_neighbours):
    name = name + "_cascade.xml"
    global folders
    rem_ext(folders[1], ".txt")
    rem_ext(folders[3], ".txt")
    ts.tester(cwd + "/" + name, folders[1], folders[3], min_size, scale_factor,
              min_neighbours)
Example #4
0
def main(cfgs):
    trans_in_test = transforms.Compose([
        transforms.ToTensor(),
        transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
    ])

    dataset_test = data.dataset(cfgs, flag='test', trans=trans_in_test)
    tester.tester(cfgs, dataset_test)
Example #5
0
 def checkHW(self):
     plat = sys.platform.lower(
     )  # try to detect the OS so that a device can be selected...
     print "checked platform"
     if plat[:5] == 'linux': opSys = "NIX"
     elif plat == 'win32': opSys = "WIN"
     else: opSys = "WIN"
     tester(opSys, self.currentHW).test1(self.ui.textBrowser)
Example #6
0
def run(RUN_TRAIN, RUN_TEST, RUN_TRAIN2, RUN_TEST2, RUN_SAVE):
    tools.initializer()
    if RUN_TRAIN : trainer()
    if RUN_TEST : tester()
    if RUN_TRAIN2 : trainer(type_=2)
    if RUN_TEST2 : tester(type_=2)
    if RUN_SAVE: tools.saver()
    if RUN_DENSECRF : crf_runner(LOAD_MAT_FILE, RUN_TRAIN2)
    if GRID_SEARCH : grid_search(LOAD_MAT_FILE, RUN_TRAIN2) 
Example #7
0
def run(RUN_TRAIN, RUN_TEST, RUN_TRAIN2, RUN_TEST2, RUN_SAVE):
    tools.mkdir()
    if RUN_TRAIN : trainer()
    if RUN_TEST : tester()
    if RUN_TRAIN2 : trainer(type_=2)
    if RUN_TEST2 : tester(type_=2)
    if RUN_SAVE: tools.saver()
    if RUN_DENSECRF : crf_runner(LOAD_MAT_FILE, RUN_TRAIN2)
    if GRID_SEARCH : grid_search(LOAD_MAT_FILE, RUN_TRAIN2) 
Example #8
0
def getScore(filePath, query):
    score_to_series = {}
    with open(filePath, "r+") as in_file:
        for line in in_file:
            line_list = line.split('\t')
            try:
                score_to_series[line_list[1].strip()] = line_list[0].strip()
            except:
                print("Line List : {}".format(line_list))
                print("Error was found in {}".format(filePath))
    scores = []
    toTest = [1, 10, 100]
    for topNum in toTest:
        try:
            topResults = getXTopResults(topNum, score_to_series)
        except:
            print("\n")
            print(f"FILEPATH : {filePath}")
            print(f"QUERY : {query}")
            print(f"Length of score_to_series : {len(score_to_series)}")
            print(f"top num : {topNum}")
        myTester = tester()
        myTester.whichQuery(query)
        score = myTester.returnPercent(topResults)
        scores.append(score)
    return scores
Example #9
0
def getScore(filePath):
    score_to_series = {}
    with open(filePath, "r+") as in_file:
        for line in in_file:
            line_list = line.split('-')
            try:
                score_to_series[line_list[1].strip()] = line_list[0].strip()
            except:
                print("Line List : {}".format(line_list))
                print("Error was found in {}".format(filePath))
    ##########################
    #Get top 10, 20, 50, 100, 200 results and get a percentage
    scores = []
    toTest = [1, 10, 100, 1000, 10000]
    #toTest = [10,20,50,100,200]
    #toTest = [1,10,800]
    #print()
    #print("SCORE_TO_SERIES LENGTH : {}".format(len(score_to_series)))
    #print()
    for topNum in toTest:
        topResults = getXTopResults(topNum, score_to_series)
        myTester = tester()
        filePathList = filePath.split('/')
        queryNum = int(filePathList[4][0])
        myTester.whichQuery(queryNum)
        score = myTester.returnPercent(topResults)
        scores.append(score)
    return scores
Example #10
0
def main():
    if len(sys.argv) > 2:
        usage_message()
        sys.exit(2)
    if len(sys.argv) == 1:
        try:
            with open('cin.fs19', 'w+') as f:
                f.write(raw_input())
                cin = f.name
        except IOError as x:
            if x.errno == errno.EACCES:
                print 'Error: Cannot write file'
                print 'Exiting...', sys.argv[0]
                sys.exit(1)
        filename = validate_file(str(cin))
        tester.tester(filename)
    if len(sys.argv) == 2:
        filename = validate_file(str(sys.argv[1]))
        tester.tester(filename)
def main():

    # add arguments
    parser = argparse.ArgumentParser()

    # loggings parameters
    parser.add_argument('--logs',
                        type=str,
                        default=None,
                        help='logs by tensorboardX')
    parser.add_argument('--local_test',
                        type=str2bool,
                        default=False,
                        help='local test verbose')
    parser.add_argument('--model_name',
                        type=str,
                        default="dcgan",
                        help='model name for saving')
    parser.add_argument('--test',
                        type=str2bool,
                        default=False,
                        help='call tester.py')
    parser.add_argument('--use_visdom',
                        type=str2bool,
                        default=False,
                        help='visualization by visdom')
    args = parser.parse_args()

    # list params
    params.print_params()

    # run program
    if args.test == False:
        trainer(args)
    else:
        tester(args)
Example #12
0
def tester_folder(cnn_dirs,
                  folders,
                  batch_size,
                  time,
                  feature,
                  workers,
                  intensity_cut,
                  leakage,
                  gpu_fraction,
                  test_indexes=None):

    cnns = get_all_networks(cnn_dirs)

    for model in cnns:
        tester(folders=folders,
               model=model,
               batch_size=batch_size,
               time=time,
               feature=feature,
               workers=workers,
               intensity_cut=intensity_cut,
               leakage=leakage,
               gpu_fraction=gpu_fraction,
               test_indexes=test_indexes)
Example #13
0
def testheuristic(MAX_I,
                  MAX_TIME_SECOND,
                  MAX_PER_ITERATION,
                  c_func,
                  heuristic,
                  args=None):
    i = 1
    ans = []
    while i <= MAX_I:
        print(i)
        i += 1
        cur = []
        time_beginning = time.time()
        cnt = 0
        while time.time(
        ) < MAX_TIME_SECOND + time_beginning and cnt < MAX_PER_ITERATION:
            cnt += 1
            x = tester.tester(c_func(i), i, heuristic, args=args)
            cur.append(x)
        ans.append((i, cur))
        if time.time() - time_beginning > 2 * MAX_TIME_SECOND:
            break
    return ans
Example #14
0
if __name__ == "__main__":
	args = argsparse(argv[1:])
	
	url = args.url
	depth = args.depth
	logfile = args.logfile
	loglevel = args.loglevel
	dbfile = args.dbfile
	threads = args.thread
	keyword = args.key
	testself = args.testself
	
	
	if testself is True:# 程序自测
		tester()
		exit(1)
	
	tasks = [url,]
	logger(logfile, loglevel)# 启动日志
	
	dbpool = Storepool(dbfile)# 启动数据库
	dbpool.createtable()
	
	analysis = Analysis(dbpool, keyword)# 启动页面分析模块
	linkpool = Linkpool(depth=depth)# 启动链接管理池
	fetchpool = Fetchpool(analysis, linkpool)# 启动爬虫工厂
	threadpool = Threadpool(fetchpool.fetcher())# 建立线程池
	threadpool.add(tasks)# 添加任务
	status = Status(threadpool, linkpool)# 创建状态反馈模块
	status.display()# 启动状态反馈模块
Example #15
0
import tester
import numpy

t=tester.tester()

t.dotest_creation()

print 'testing array'
iarr = numpy.arange(9,dtype='f4')

t.dotest_fromobj(iarr)
print 'After call: ',iarr

print '\ntesting scalar'
iarr = numpy.array(3,dtype='f4')
t.dotest_fromobj(iarr)
print 'After call: ',iarr

print '\ntesting array scalar i2'
iarr = numpy.array(223,dtype='i2')
t.dotest_fromobj(iarr)
print 'After call: ',iarr

print '\ntesting python scalar float'
iarr = 8.6
t.dotest_fromobj(iarr)
print 'After call: ',iarr


print '\ntesting getting output'
tmp = t.dotest_output()
Example #16
0
    def saveCfileAndCompile(self, C_txt, displayOutputPlace, currentHW):
        import subprocess
        from subprocess import PIPE
        import sys
        import os
        import time
        from tester import tester

        QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
        #print "current dir:", os.getcwd()
        #os.chdir("../helpers/hexes")
        #print "current dir:", os.getcwd()
        #commands:
        #note: aavrgcc commands are here, but Arduino Avrdude commands are in tester.py
        #LINUX
        if currentHW == "ArduinoUno" and self.opSys == "NIX":
            commandListo = r"../avr/bin/avr-gcc -x c -I. -g -mmcu=atmega328 -DF_CPU=16000000UL -Os -fpack-struct -fshort-enums -funsigned-bitfields -funsigned-char -Wall -std=gnu99 -Wa,-ahlms=LADDER.lst -c "
            commandOut = r"../avr/bin/avr-gcc  -I. -T ../avr/lib/ldscripts/avr5.x -Wl,-Map,LADDER.out.map  -mmcu=atmega328 -lm -o LADDER.out "
            commandHex = r"../avr/bin/avr-objcopy -j .text -j .data -O ihex LADDER.out LADDER.hex"
            commandAvrDude = tester(self.opSys,
                                    currentHW).test1(displayOutputPlace)[0]

        if currentHW == "ArduinoNano" and self.opSys == "NIX":
            commandListo = r"../avr/bin/avr-gcc -x c -I. -g -mmcu=atmega328 -DF_CPU=16000000UL -Os -fpack-struct -fshort-enums -funsigned-bitfields -funsigned-char -Wall -std=gnu99 -Wa,-ahlms=LADDER.lst -c "
            commandOut = r"../avr/bin/avr-gcc  -I. -T ../avr/lib/ldscripts/avr5.x -Wl,-Map,LADDER.out.map  -mmcu=atmega328 -lm -o LADDER.out "
            commandHex = r"../avr/bin/avr-objcopy -j .text -j .data -O ihex LADDER.out LADDER.hex"
            commandAvrDude = tester(self.opSys,
                                    currentHW).test1(displayOutputPlace)[0]

        if currentHW == "ArduinoMega" and self.opSys == "NIX":
            commandListo = r"../avr/bin/avr-gcc -x c -I. -g -mmcu=atmega2560 -DF_CPU=16000000UL -Os -fpack-struct -fshort-enums -funsigned-bitfields -funsigned-char -Wall -std=gnu99 -Wa,-ahlms=LADDER.lst -c "
            commandOut = r"../avr/bin/avr-gcc  -I. -T ../avr/lib/ldscripts/avr6.x -Wl,-Map,LADDER.out.map  -mmcu=atmega2560 -lm -o LADDER.out "
            commandHex = r"../avr/bin/avr-objcopy -j .text -j .data -O ihex LADDER.out LADDER.hex"
            commandAvrDude = tester(self.opSys,
                                    currentHW).test1(displayOutputPlace)[0]

        #MAC
        if currentHW == "ArduinoUno" and self.opSys == "MAC":
            commandListo = r"avr-gcc -x c -I. -g -mmcu=atmega328 -DF_CPU=16000000UL -Os -fpack-struct -fshort-enums -funsigned-bitfields -funsigned-char -Wall -std=gnu99 -Wa,-ahlms=LADDER.lst -c "
            commandOut = r"avr-gcc  -I. -Wl,-Map,LADDER.out.map  -mmcu=atmega328 -lm -o LADDER.out "
            commandHex = r"avr-objcopy -j .text -j .data -O ihex LADDER.out LADDER.hex"
            commandAvrDude = tester(self.opSys,
                                    currentHW).test1(displayOutputPlace)[0]

        if currentHW == "ArduinoNano" and self.opSys == "MAC":
            commandListo = r"avr-gcc -x c -I. -g -mmcu=atmega328 -DF_CPU=16000000UL -Os -fpack-struct -fshort-enums -funsigned-bitfields -funsigned-char -Wall -std=gnu99 -Wa,-ahlms=LADDER.lst -c "
            commandOut = r"avr-gcc  -I. -Wl,-Map,LADDER.out.map  -mmcu=atmega328 -lm -o LADDER.out "
            commandHex = r"avr-objcopy -j .text -j .data -O ihex LADDER.out LADDER.hex"
            commandAvrDude = tester(self.opSys,
                                    currentHW).test1(displayOutputPlace)[0]

        if currentHW == "ArduinoMega" and self.opSys == "MAC":
            commandListo = r"avr-gcc -x c -I. -g -mmcu=atmega2560 -DF_CPU=16000000UL -Os -fpack-struct -fshort-enums -funsigned-bitfields -funsigned-char -Wall -std=gnu99 -Wa,-ahlms=LADDER.lst -c "
            commandOut = r"avr-gcc  -I. -Wl,-Map,LADDER.out.map  -mmcu=atmega2560 -lm -o LADDER.out "
            commandHex = r"avr-objcopy -j .text -j .data -O ihex LADDER.out LADDER.hex"
            commandAvrDude = tester(self.opSys,
                                    currentHW).test1(displayOutputPlace)[0]

        #WINDOWS
        if currentHW == "ArduinoUno" and self.opSys == "WIN":
            commandListo = r"..\\WinAVR\\bin\\avr-gcc.exe -x c -I. -g -mmcu=atmega328 -DF_CPU=16000000UL -Os -fpack-struct -fshort-enums -funsigned-bitfields -funsigned-char -Wall -std=gnu99 -Wa,-ahlms=LADDER.lst -c "
            commandOut = r"..\\WinAVR\\bin\\avr-gcc.exe  -I. -Wl,-Map,LADDER.out.map  -mmcu=atmega328 -lm -o LADDER.out "
            commandHex = r"..\\WinAVR\\bin\\avr-objcopy.exe -j .text -j .data -O ihex LADDER.out LADDER.hex"
            commandAvrDude = tester(self.opSys,
                                    currentHW).test1(displayOutputPlace)[0]
        if currentHW == "ArduinoNano" and self.opSys == "WIN":
            commandListo = r"..\\WinAVR\\bin\\avr-gcc.exe -x c -I. -g -mmcu=atmega328 -DF_CPU=16000000UL -Os -fpack-struct -fshort-enums -funsigned-bitfields -funsigned-char -Wall -std=gnu99 -Wa,-ahlms=LADDER.lst -c "
            commandOut = r"..\\WinAVR\\bin\\avr-gcc.exe  -I. -Wl,-Map,LADDER.out.map  -mmcu=atmega328 -lm -o LADDER.out "
            commandHex = r"..\\WinAVR\\bin\\avr-objcopy.exe -j .text -j .data -O ihex LADDER.out LADDER.hex"
            commandAvrDude = tester(self.opSys,
                                    currentHW).test1(displayOutputPlace)[0]

        if currentHW == "ArduinoMega" and self.opSys == "WIN":
            commandListo = r"..\\WinAVR\\bin\\avr-gcc.exe -x c -I. -g -mmcu=atmega2560 -DF_CPU=16000000UL -Os -fpack-struct -fshort-enums -funsigned-bitfields -funsigned-char -Wall -std=gnu99 -Wa,-ahlms=LADDER.lst -c "
            commandOut = r"..\\WinAVR\\bin\\avr-gcc.exe  -I. -Wl,-Map,LADDER.out.map  -mmcu=atmega2560 -lm -o LADDER.out "
            commandHex = r"..\\WinAVR\\bin\\avr-objcopy.exe -j .text -j .data -O ihex LADDER.out LADDER.hex"
            commandAvrDude = tester(self.opSys,
                                    currentHW).test1(displayOutputPlace)[0]

#####run commands:

        print "current dir:", os.getcwd()
        os.chdir("../helpers/hexes")
        print "current dir:", os.getcwd()

        f = open('LLCode', 'w')
        f.write(C_txt)
        f.close(
        )  # file is not immediately deleted because we used delete=False
        filename = 'LLCode'

        ###ADDED BY MIGUEL
        # MIGUEL 13
        ''' THIS CODE COPIES THE uart.c and uark.h FILES TO THE HEXES FOLDER TO COMPILE THE GENERATED
            C CODE. THE LAST SECTION AIMS TO ADD PORTABLE FEATURES TO THE PROGRAM IN LINUX SYSTEMS.
        '''
        from shutil import copy2
        if self.opSys == "NIX":
            copy2("../uart.h", os.getcwd())
            copy2("../uart.c", os.getcwd())

        if self.opSys == "MAC":
            copy2("../uart.h", os.getcwd())
            copy2("../uart.c", os.getcwd())

        if self.opSys == "WIN":
            copy2("..\uart.h", os.getcwd())
            copy2("..\uart.c", os.getcwd())

        if self.opSys == "NIX":
            print "Setting Envirenment Path for library in Linux"
            Lib = "../avr/lib"
            os.environ['LD_LIBRARY_PATH'] = Lib

        ### END MIGUEL

        commandwfile = commandListo
        commandwfile = commandwfile + filename
        print commandwfile

        #p = subprocess.Popen(commandwfile, shell=True, cwd=r"./hexes")#linux
        p = subprocess.Popen(commandwfile, shell=True)
        while p.poll() is None:  # polls to see if the programming is done
            time.sleep(0.5)
        print "Process ended, ret code", p.returncode
        #displayOutputPlace.clear()
        if p.returncode != 0:
            displayOutputPlace.append("lst and o failed")
        if p.returncode == 0:
            displayOutputPlace.append(".lst and .o file generated")

        commandwfile = commandOut + filename + ".o"
        p = subprocess.Popen(commandwfile, shell=True)
        while p.poll() is None:  # polls to see if the programming is done
            time.sleep(0.5)
        #print "Process ended, ret code:", p.returncode
        if p.returncode != 0:
            displayOutputPlace.append("out file failed")
        if p.returncode == 0:
            displayOutputPlace.append("out file generated")

        commandwfile = commandHex
        p = subprocess.Popen(commandwfile, shell=True)
        while p.poll() is None:  # polls to see if the programming is done
            time.sleep(0.5)
        #print "Process ended, ret code:", p.returncode
        if p.returncode != 0:
            displayOutputPlace.append("hex file failed")
        if p.returncode == 0:
            displayOutputPlace.append("hex file generated")

        if commandAvrDude != None:
            displayOutputPlace.append("checking port and programming")
            commandwfile = commandAvrDude + " -U flash:w:LADDER.hex:i"
            print "command", commandwfile
            p = subprocess.Popen(commandwfile,
                                 shell=True,
                                 stdout=PIPE,
                                 stderr=PIPE)
            while p.poll() is None:  # polls to see if the programming is done
                time.sleep(0.5)
            print "P outut:", p.communicate()
            if p.returncode != 0:
                displayOutputPlace.append("upload failed")
            if p.returncode == 0:
                displayOutputPlace.append("Hex file uploaded")
            else:
                print("progrmming error")
            """
            #p = subprocess.Popen(commandwfile,stdout = subprocess.PIPE, stderr= subprocess.PIPE,shell=True).communicate()
               
            #output,error =p
            #print"avrdude errstream", error
            """
        if commandAvrDude == None:
            displayOutputPlace.append("Hardware: " + currentHW + " Not found")
        #delete all temp files:
        os.unlink(f.name)

        import os
        import shutil
        #delete temp files:
        if "hexes" in os.getcwd():

            for root, dirs, files in os.walk("./"):
                for f in files:
                    os.unlink(os.path.join(root, f))
                for d in dirs:
                    shutil.rmtree(os.path.join(root, d))
            time.sleep(1)
        else:
            print "in wrong place, not deleting!"
        QApplication.restoreOverrideCursor()
        os.chdir("../")
        os.chdir("../")
        print "current dir:", os.getcwd()
        os.chdir("./program")
        print "current dir:", os.getcwd()
Example #17
0
from tester import tester

t = tester()

t.whichQuery(1)

series = [
    "GSE47860", "GSE47861", "GSE72295", "GSE27175", "GSE19829", "GSE55699",
    "GSE60995", "GSE60494", "GSE73923", "GSE121382", "GSE69428", "GSE69429",
    "GSE92241", "GSE51260", "GSE133987", "GSE56443", "GSE66387", "GSE76360"
]

score = t.returnScore(series)

print(score)
def main():
    ## get contract and init pint
    vote.contract._populate_empty_checkers()
    print "operation\t\tmean (s)\t\tsd (s)\t\truns"

    # ---------------------------------------------------------
    # get functions
    # ---------------------------------------------------------
    # params
    params = setup()
    (tally_priv, tally_pub) = key_gen(params)
    (voter1_priv, voter1_pub) = key_gen(params)
    options = ['alice', 'bob']
    participants = [pack(voter1_pub)]

    # init
    init_tx = vote.init()
    token = init_tx['transaction']['outputs'][0]

    # create vote
    create_vote_tx = vote.create_vote((token, ), None, None, dumps(options),
                                      dumps(participants), pack(tally_priv),
                                      pack(tally_pub))
    vote_obj = create_vote_tx['transaction']['outputs'][1]

    # add vote
    add_vote_tx = vote.add_vote((vote_obj, ), None, None, dumps([1]),
                                pack(voter1_priv), pack(voter1_pub))

    # tally
    last_vote_obj = add_vote_tx['transaction']['outputs'][0]
    tally_tx = vote.tally((last_vote_obj, ), None, None, pack(tally_priv),
                          pack(tally_pub))

    # ---------------------------------------------------------
    # test create_vote
    # ---------------------------------------------------------
    # [gen]
    tester(RUNS, "create_vote [g]", vote.create_vote, (token, ), None, None,
           dumps(options), dumps(participants), pack(tally_priv),
           pack(tally_pub))
    # [check]
    solution = transaction_to_solution(create_vote_tx)
    tester(
        RUNS,
        "create_vote [c]",
        vote.contract.checkers['create_vote'],
        solution['inputs'],
        solution['referenceInputs'],
        solution['parameters'],
        solution['outputs'],
        solution['returns'],
        solution['dependencies'],
    )

    # ---------------------------------------------------------
    # test add_vote
    # ---------------------------------------------------------
    # [gen]
    tester(RUNS, "add_vote [g]\t", vote.add_vote, (vote_obj, ), None, None,
           dumps([1, 0]), pack(voter1_priv), pack(voter1_pub))
    # [check]
    solution = transaction_to_solution(add_vote_tx)
    tester(
        RUNS,
        "add_vote [c]\t",
        vote.contract.checkers['add_vote'],
        solution['inputs'],
        solution['referenceInputs'],
        solution['parameters'],
        solution['outputs'],
        solution['returns'],
        solution['dependencies'],
    )

    # ---------------------------------------------------------
    # test compute bill
    # ---------------------------------------------------------
    # [gen]
    tester(RUNS, "tally [g]\t", vote.tally, (last_vote_obj, ), None, None,
           pack(tally_priv), pack(tally_pub))
    # [check]
    solution = transaction_to_solution(tally_tx)
    tester(
        RUNS,
        "tally [c]\t",
        vote.contract.checkers['tally'],
        solution['inputs'],
        solution['referenceInputs'],
        solution['parameters'],
        solution['outputs'],
        solution['returns'],
        solution['dependencies'],
    )
Example #19
0
File: main.py Project: yk287/ML
trainloader = torch.utils.data.DataLoader(trainset,
                                          batch_size=opts.batch,
                                          shuffle=True)

testset = datasets.FashionMNIST('FMNIST_data/',
                                download=True,
                                train=False,
                                transform=transform)
testloader = torch.utils.data.DataLoader(testset, batch_size=1, shuffle=False)

import trainer
from tester import tester

#Hyperparameters for our network

output_size = opts.num_classes
model = discriminator(opts).to(device)

criterion = nn.CrossEntropyLoss()
optimizer = optim.Adam(model.parameters(),
                       lr=opts.lr,
                       betas=(opts.beta1, opts.beta2))

#trains the model
trainer = trainer.trainer(opts, trainloader, model, optimizer, criterion)
trainer.train()

#trains the model
tester = tester(opts, testloader, model)
tester.test()
Example #20
0
from tester import tester
from tqdm import tqdm
import random
t = tester(['python3', '../D1.py'], ['../D1_yj'])

random.seed(0)
for i in tqdm(range(10000)):
    A = random.randint(3, 7)
    B = random.randint(3, 7)
    while B % 2 != 0 and A % 2 != 0:
        B = random.randint(3, 20)
    C = random.randint(1, (A * B) // 2)
    T = 1
    tc = f'{T}\n'
    for i in range(T):
        tc += f'{A} {B} {C}\n'
    equal, right, wrong = t.test(tc)
    if not equal:
        print('Case:')
        print(tc)
        print('Answer:')
        print(right)
        print('Output:')
        print(wrong)
Example #21
0
def main():
    ## get contract and init pint
    bank_authenticated.contract._populate_empty_checkers()
    print "operation\t\tmean (s)\t\tsd (s)\t\truns"

    # ---------------------------------------------------------
    # get functions
    # ---------------------------------------------------------
    # params
    params = setup()
    (alice_priv, alice_pub) = key_gen(params)
    (_, bob_pub) = key_gen(params)

    # init
    init_tx = bank_authenticated.init()
    token = init_tx['transaction']['outputs'][0]

    # create accounts
    create_alice_account_tx = bank_authenticated.create_account(
        (token, ), None, None, pack(alice_pub))
    create_bob_account_tx = bank_authenticated.create_account((token, ), None,
                                                              None,
                                                              pack(bob_pub))
    alice_account = create_alice_account_tx['transaction']['outputs'][1]
    bob_account = create_bob_account_tx['transaction']['outputs'][1]

    # make transfer
    auth_transfer_tx = bank_authenticated.auth_transfer(
        (alice_account, bob_account), None, ('3', ), pack(alice_priv))

    # ---------------------------------------------------------
    # test create_account
    # ---------------------------------------------------------
    # [gen]
    tester(RUNS, "create_account [g]", bank_authenticated.create_account,
           (token, ), None, None, pack(alice_pub))
    # [check]
    solution = transaction_to_solution(create_alice_account_tx)
    tester(
        RUNS,
        "create_account [c]",
        bank_authenticated.contract.checkers['create_account'],
        solution['inputs'],
        solution['referenceInputs'],
        solution['parameters'],
        solution['outputs'],
        solution['returns'],
        solution['dependencies'],
    )

    # ---------------------------------------------------------
    # test transfer
    # ---------------------------------------------------------
    # [gen]
    tester(RUNS, "auth_transfer [g]", bank_authenticated.auth_transfer,
           (alice_account, bob_account), None, ('3', ), pack(alice_priv))
    # [gen]
    solution = transaction_to_solution(auth_transfer_tx)
    tester(
        RUNS,
        "auth_transfer [c]",
        bank_authenticated.contract.checkers['auth_transfer'],
        solution['inputs'],
        solution['referenceInputs'],
        solution['parameters'],
        solution['outputs'],
        solution['returns'],
        solution['dependencies'],
    )
Example #22
0
    def saveCfileAndCompile(self,C_txt,displayOutputPlace,currentHW, flag):
        import subprocess
        from subprocess import PIPE
        import sys
        import os
        import time
        from tester import tester
        self.__class__.pyDir=os.getcwd()
        self.__class__.helpDir= self.__class__.pyDir + r"/../helpers/hexes/"
        self.readPath()
        QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
        #print "current dir:", os.getcwd()
        #os.chdir("../helpers/hexes")
        #print "current dir:", os.getcwd()
        #commands:
        #note: aavrgcc commands are here, but Arduino Avrdude commands are in tester.py
        #LINUX
        print "HexMaker: mainWindowUI.projectName" ,  self.__class__.projectName
        print "HexMaker: mainWindowUI.currentdir" ,  self.__class__.currentFileDir
        if self.__class__.projectName == None:
            import main
            main.mainWindowUI().saveFileAs()
        if self.__class__.projectName == None:
            return
        filename=ntpath.basename(self.__class__.projectName)
        if currentHW == "Waltech" and self.opSys == "NIX":
            commandListo = r"../avr/bin/avr-gcc -x c -I. -g -mmcu=atmega32 -DF_CPU=4000000UL -Os -fpack-struct -fshort-enums -funsigned-bitfields -funsigned-char -Wall -std=gnu99 -Wa,-ahlms=" + filename + ".lst -c "
            commandOut = r"../avr/bin/avr-gcc  -I. -T " + self.__class__.pyDir + "/../helpers/avr/lib/ldscripts/avr5.x -Wl,-Map," + filename + ".out.map  -mmcu=atmega32 -lm -o " + filename + ".out " 
            commandHex = r"../avr/bin/avr-objcopy -j .text -j .data -O ihex " + filename + ".out " + filename + ".hex"
            self.commandAvrDude = r"../avrdude  -C ../avrdude.conf -p m32 -P usb -c usbtiny -B5"

        if currentHW == "ArduinoUno" and self.opSys == "NIX":
            commandListo = r"../avr/bin/avr-gcc -x c -I. -g -mmcu=atmega328 -DF_CPU=16000000UL -Os -fpack-struct -fshort-enums -funsigned-bitfields -funsigned-char -Wall -std=gnu99 -Wa,-ahlms="+ filename +".lst -c "
            commandOut = r"../avr/bin/avr-gcc  -I. -T " + self.__class__.pyDir + "/../helpers/avr/lib/ldscripts/avr5.x -Wl,-Map," + filename + ".out.map  -mmcu=atmega328 -lm -o " + filename + ".out " 
            commandHex = r"../avr/bin/avr-objcopy -j .text -j .data -O ihex "+ filename + ".out " + filename + ".hex"
            self.commandAvrDude =tester(self.opSys,currentHW).test1(displayOutputPlace)
            
        if currentHW == "ArduinoNano" and self.opSys == "NIX":
            commandListo = r"../avr/bin/avr-gcc -x c -I. -g -mmcu=atmega328 -DF_CPU=16000000UL -Os -fpack-struct -fshort-enums -funsigned-bitfields -funsigned-char -Wall -std=gnu99 -Wa,-ahlms=" + filename + ".lst -c "
            commandOut = r"../avr/bin/avr-gcc  -I. -T " + self.__class__.pyDir + "/../helpers/avr/lib/ldscripts/avr5.x -Wl,-Map," + filename + ".out.map  -mmcu=atmega328 -lm -o " + filename + ".out " 
            commandHex = r"../avr/bin/avr-objcopy -j .text -j .data -O ihex "+ filename +".out " + filename + ".hex"
            self.commandAvrDude =tester(self.opSys,currentHW).test1(displayOutputPlace)
     
        if currentHW == "ArduinoMega" and self.opSys == "NIX":
            commandListo = r"../avr/bin/avr-gcc -x c -I. -g -mmcu=atmega2560 -DF_CPU=16000000UL -Os -fpack-struct -fshort-enums -funsigned-bitfields -funsigned-char -Wall -std=gnu99 -Wa,-ahlms=" + filename + ".lst -c "
            commandOut = r"../avr/bin/avr-gcc  -I. -T " + self.__class__.pyDir + "/../helpers/avr/lib/ldscripts/avr6.x -Wl,-Map," + filename + ".out.map  -mmcu=atmega2560 -lm -o " + filename + ".out " 
            commandHex = r"../avr/bin/avr-objcopy -j .text -j .data -O ihex " + filename + ".out " + filename +".hex"
            self.commandAvrDude =tester(self.opSys,currentHW).test1(displayOutputPlace)
            
        #MAC
        if currentHW == "Waltech" and self.opSys == "MAC":
            commandListo = r"avr-gcc -x c -I. -g -mmcu=atmega32 -DF_CPU=4000000UL -Os -fpack-struct -fshort-enums -funsigned-bitfields -funsigned-char -Wall -std=gnu99 -Wa,-ahlms=" + filename +".lst -c "
            commandOut = r"avr-gcc  -I. -Wl,-Map,"+ filename + ".out.map  -mmcu=atmega32 -lm -o " + filename + ".out " 
            commandHex = r"avr-objcopy -j .text -j .data -O ihex " + filename + ".out " + filename + ".hex"
            self.commandAvrDude = r"avrdude  -C ../avrdude.conf -p m32 -P usb -c usbtiny -B5"
        if currentHW == "ArduinoUno" and self.opSys == "MAC":
            commandListo = r"avr-gcc -x c -I. -g -mmcu=atmega328 -DF_CPU=16000000UL -Os -fpack-struct -fshort-enums -funsigned-bitfields -funsigned-char -Wall -std=gnu99 -Wa,-ahlms=" + filename + ".lst -c "
            commandOut = r"avr-gcc  -I. -Wl,-Map," + filename + ".out.map  -mmcu=atmega328 -lm -o " + filename + ".out " 
            commandHex = r"avr-objcopy -j .text -j .data -O ihex " + filename + ".out " + filename + ".hex"
            self.commandAvrDude =tester(self.opSys,currentHW).test1(displayOutputPlace)
            
        if currentHW == "ArduinoNano" and self.opSys == "MAC":
            commandListo = r"avr-gcc -x c -I. -g -mmcu=atmega328 -DF_CPU=16000000UL -Os -fpack-struct -fshort-enums -funsigned-bitfields -funsigned-char -Wall -std=gnu99 -Wa,-ahlms=" + filename + ".lst -c "
            commandOut = r"avr-gcc  -I. -Wl,-Map," + filename + ".out.map  -mmcu=atmega328 -lm -o " + filename + ".out " 
            commandHex = r"avr-objcopy -j .text -j .data -O ihex " + filename + ".out " + filename + ".hex"
            self.commandAvrDude =tester(self.opSys,currentHW).test1(displayOutputPlace)
       
        if currentHW == "ArduinoMega" and self.opSys == "MAC":
            commandListo = r"avr-gcc -x c -I. -g -mmcu=atmega2560 -DF_CPU=16000000UL -Os -fpack-struct -fshort-enums -funsigned-bitfields -funsigned-char -Wall -std=gnu99 -Wa,-ahlms=" + filename + ".lst -c "
            commandOut = r"avr-gcc  -I. -Wl,-Map," + filename + ".out.map  -mmcu=atmega2560 -lm -o " + filename + ".out " 
            commandHex = r"avr-objcopy -j .text -j .data -O ihex " + filename + ".out " + filename + ".hex"
            self.commandAvrDude =tester(self.opSys,currentHW).test1(displayOutputPlace)
       
        #WINDOWS
        if currentHW == "Waltech" and self.opSys == "WIN":
            commandListo = r"..\\WinAVR\\bin\\avr-gcc.exe -x c -I. -g -mmcu=atmega32 -DF_CPU=4000000UL -Os -fpack-struct -fshort-enums -funsigned-bitfields -funsigned-char -Wall -std=gnu99 -Wa,-ahlms=" + filename + ".lst -c "
            commandOut =r"..\\WinAVR\\bin\\avr-gcc.exe  -I. -Wl,-Map," + filename + ".out.map  -mmcu=atmega32 -lm -o " + filename + ".out " 
            commandHex = r"..\\WinAVR\\bin\\avr-objcopy.exe -j .text -j .data -O ihex " + filename + ".out " + filename +".hex"
            self.commandAvrDude = r"..\\WinAVR\\bin\\avrdude.exe -p m32 -P usb -c usbtiny -B5"
        if currentHW == "ArduinoUno" and self.opSys == "WIN":
            commandListo = r"..\\WinAVR\\bin\\avr-gcc.exe -x c -I. -g -mmcu=atmega328 -DF_CPU=16000000UL -Os -fpack-struct -fshort-enums -funsigned-bitfields -funsigned-char -Wall -std=gnu99 -Wa,-ahlms=" + filename +".lst -c "
            commandOut =r"..\\WinAVR\\bin\\avr-gcc.exe  -I. -Wl,-Map," + filename + ".out.map  -mmcu=atmega328 -lm -o " + filename + ".out " 
            commandHex = r"..\\WinAVR\\bin\\avr-objcopy.exe -j .text -j .data -O ihex " + filename + ".out " + filename + ".hex"
            self.commandAvrDude =tester(self.opSys,currentHW).test1(displayOutputPlace)
        if currentHW == "ArduinoNano" and self.opSys == "WIN":
            commandListo = r"..\\WinAVR\\bin\\avr-gcc.exe -x c -I. -g -mmcu=atmega328 -DF_CPU=16000000UL -Os -fpack-struct -fshort-enums -funsigned-bitfields -funsigned-char -Wall -std=gnu99 -Wa,-ahlms=" + filename + ".lst -c "
            commandOut =r"..\\WinAVR\\bin\\avr-gcc.exe  -I. -Wl,-Map," + filename + ".out.map  -mmcu=atmega328 -lm -o " + filename + ".out " 
            commandHex = r"..\\WinAVR\\bin\\avr-objcopy.exe -j .text -j .data -O ihex " + filename + ".out " + filename + ".hex"
            self.commandAvrDude =tester(self.opSys,currentHW).test1(displayOutputPlace)
            
        if currentHW == "ArduinoMega" and self.opSys == "WIN":
            commandListo = r"..\\WinAVR\\bin\\avr-gcc.exe -x c -I. -g -mmcu=atmega2560 -DF_CPU=16000000UL -Os -fpack-struct -fshort-enums -funsigned-bitfields -funsigned-char -Wall -std=gnu99 -Wa,-ahlms=" + filename + ".lst -c "
            commandOut =r"..\\WinAVR\\bin\\avr-gcc.exe  -I. -Wl,-Map," + filename + ".out.map  -mmcu=atmega2560 -lm -o " + filename + ".out " 
            commandHex = r"..\\WinAVR\\bin\\avr-objcopy.exe -j .text -j .data -O ihex " + filename + ".out " + filename + ".hex"
            self.commandAvrDude =tester(self.opSys,currentHW).test1(displayOutputPlace)
            
#####run commands:   
        print "current dir:", self.__class__.helpDir
        os.chdir(self.__class__.currentFileDir)
        print "current dir:", os.getcwd()
        f = open(filename + ".c", 'w')
        f.write(C_txt)
        f.close()   # file is not immediately deleted because we used delete=False
      
        commandwfile = self.__class__.helpDir + commandListo
        commandwfile = commandwfile + filename + ".c"
        print commandwfile
        
        #p = subprocess.Popen(commandwfile, shell=True, cwd=r"./hexes")#linux
        p = subprocess.Popen(commandwfile, shell=True)
        while p.poll() is None:# polls to see if the programming is done
            time.sleep(0.5)
        print "Process ended, ret code", p.returncode
        #displayOutputPlace.clear()
        if p.returncode != 0:
            displayOutputPlace.append ("lst and o failed")
        if p.returncode == 0:
            displayOutputPlace.append ( ".lst and .o file generated")
        
        commandwfile =self.__class__.helpDir + commandOut + filename + ".o"
        print self.__class__.helpDir
        print commandwfile
        p = subprocess.Popen(commandwfile, shell=True )
        while p.poll() is None:# polls to see if the programming is done
            time.sleep(0.5)
        #print "Process ended, ret code:", p.returncode
        if p.returncode != 0:
            displayOutputPlace.append ( "out file failed")
        if p.returncode == 0:
           displayOutputPlace.append ( "out file generated")
        
        
        commandwfile = self.__class__.helpDir +  commandHex      
        p = subprocess.Popen(commandwfile, shell=True)
        while p.poll() is None:# polls to see if the programming is done
            time.sleep(0.5)
        #print "Process ended, ret code:", p.returncode
        if p.returncode != 0:
            displayOutputPlace.append ( "hex file failed")
        if p.returncode == 0:
            displayOutputPlace.append ( "hex file generated")
        QApplication.restoreOverrideCursor()
        os.chdir(self.__class__.pyDir)
        if flag == "B":
            self.burnHex(displayOutputPlace)
Example #23
0
import coco_proc, tester


if __name__ == '__main__':

    loc = 'models/mlbl_model.pkl'
    z, zd, zt = coco_proc.process(context=5)
    tester.tester(loc, z, zt)
Example #24
0
from tester import tester
import random
t = tester(['python3', '../ab.py'], ['../_3_.bin'])

random.seed(1)
for i in range(10000):
    A = random.randint(10**900000, 10**1000000)
    B = random.randint(10**900000, 10**1000000)
    tc = f'{A} {B}'
    equal, right, wrong = t.test(tc)
    if not equal:
        print('Case:')
        print(tc)
        print('Answer:')
        print(right)
        print('Output:')
        print(wrong)
Example #25
0
                self.operands.append(r_operand)
        else:
            l_operand = self.operands[-1]
            self.operands.pop()
            if operation == '+':
                self.operands.append(l_operand + r_operand)
            if operation == '-':
                self.operands.append(l_operand - r_operand)
            if operation == '*':
                self.operands.append(l_operand * r_operand)
            if operation == '/':
                self.operands.append(l_operand / r_operand)


if __name__ == '__main__':
    tester("tests_for_RPN.txt", RPN)
    #while True:
    #    line = input("Введите выражение:\n")
    #    print(RPN(line).calc_with_Fraction())
"""
failed tests:
 [5, 6, 7, 8, 9, 11, 12, 14, 16, 22]
"""
"""
Введите выражение:
(y*(2x-2))/(6x-5+1) + 3y
(-1-+10*x*y-6*y)/(-2+3*x)
Введите выражение:
(y*(2x-2))/(6x-5+1) + 3y
(10*x*y-7*y)/(-2+3*x)
Введите выражение:
Example #26
0
from tester import tester
import random
t = tester(['../answer'], ['pypy3', '../_2.py'])

#random.seed(0)
for i in range(10000):
    N = random.randint(1, 6)
    S = random.randint(-10, 10)
    tc = f"{N} {S}\n"
    for i in range(N):
        tc += str(random.randint(-10, 10))+" "
    tc += '\n'
    equal, right, wrong = t.test(tc)
    if not equal:
        print('Case:')
        print(tc)
        print('Answer:')
        print(right)
        print('Output:')
        print(wrong)
Example #27
0
from tester import tester
import random

t = tester(['../10254.right'], ['../10254.bin'])

random.seed(1)
for i in range(100000):
    T = random.randint(1, 1)
    tc = f'{T}\n'
    for _ in range(T):
        N = random.randint(10, 10)
        tc += f'{N}\n'
        for _ in range(N):
            tc += f'{random.randint(-10000000, 10000000)} {random.randint(-10000000, 10000000)}\n'
    _equal, right, wrong = t.test(tc)
    a, b, c, d = map(int, right.split())
    rv = (a - c)**2 + (b - d)**2
    a, b, c, d = map(int, wrong.split())
    wv = (a - c)**2 + (b - d)**2
    equal = rv == wv
    if not equal:
        print('Case:')
        print(tc)
        print('Answer:')
        print(right)
        print(rv)
        print('Output:')
        print(wrong)
        print(wv)
Example #28
0
            os.remove(os.path.join(root, name))
        for name in dirs:
            os.rmdir(os.path.join(root, name))
else:
    os.mkdir('runtime')
os.chdir('runtime')
os.mkdir('inputs')
os.mkdir('outputs')


if(contest_url != ''):
    scrapper.contest_page_scrapper(contest_url)
else:
    scrapper.problem_page_scrapper(problem_url)

user_input = ''
tester = tester.tester(path)
while True:
    user_input = input("input : ")
    if user_input == 'exit':
        break
    try:
        if(os.listdir().count('your_output_temp.txt')) != 0:
            os.remove('your_output_temp.txt')
        if platform.system() == 'Linux':
            tester.tester_linux(user_input)
        else:
            tester.tester(user_input)
    finally:
        continue
Example #29
0
def main():
    ## get contract and init pint
    smart_meter.contract._populate_empty_checkers()
    print "operation\t\tmean (s)\t\tsd (s)\t\truns"


    # ---------------------------------------------------------
    # get functions
    # ---------------------------------------------------------
    # params
    params = setup()
    G = params[0]
    (provider_priv, provider_pub) = key_gen(params)
    tariffs  = [5, 3, 5, 3, 5]
    readings = [10, 20, 30, 10, 50]
    openings = [G.order().random() for _ in tariffs]

    # init
    init_tx = smart_meter.init()
    token = init_tx['transaction']['outputs'][0]

    # create smart_meter
    create_meter_tx = smart_meter.create_meter(
        (token,),
        None,
        None,
        pack(provider_pub),
        'Some info about the meter.',   # some info about the meter
        dumps([5, 3, 5, 3, 5]),         # the tariffs
        dumps(764)                      # the billing period
    )
    meter_obj = create_meter_tx['transaction']['outputs'][1]

    # add reading
    add_reading_tx = smart_meter.add_reading(
        (meter_obj,),
        None,
        None,
        pack(provider_priv),
        dumps(10),                 # the new reading
        pack(G.order().random())   # the opening value
    )

    # compute bill
    last_meter_obj = add_reading_tx['transaction']['outputs'][0]
    compute_bill_tx = smart_meter.compute_bill(
        (last_meter_obj,),
        None,
        None,
        dumps(readings),
        pack(openings),
        dumps(tariffs)
    )


    # ---------------------------------------------------------
    # test create_meter
    # ---------------------------------------------------------
    # [gen]
    tester(RUNS, "create_meter [g]", smart_meter.create_meter,
        (token,),
        None,
        None,
        pack(provider_pub),
        'Some info about the meter.',
        dumps([5, 3, 5, 3, 5]),
        dumps(764)
    )
    # [check]
    solution = transaction_to_solution(create_meter_tx)
    tester(RUNS, "create_meter [c]", smart_meter.contract.checkers['create_meter'],
        solution['inputs'],
        solution['referenceInputs'],
        solution['parameters'],
        solution['outputs'],
        solution['returns'],
        solution['dependencies'],
    )


    # ---------------------------------------------------------
    # test add_reading
    # ---------------------------------------------------------
    # [gen]
    tester(RUNS, "add_reading [g]", smart_meter.add_reading,
        (meter_obj,),
        None,
        None,
        pack(provider_priv),
        dumps(10),
        pack(G.order().random())
    )
    # [check]
    solution = transaction_to_solution(add_reading_tx)
    tester(RUNS, "add_reading [c]", smart_meter.contract.checkers['add_reading'],
        solution['inputs'],
        solution['referenceInputs'],
        solution['parameters'],
        solution['outputs'],
        solution['returns'],
        solution['dependencies'],
    )


    # ---------------------------------------------------------
    # test compute bill
    # ---------------------------------------------------------
    # [gen]
    tester(RUNS, "compute_bill [g]", smart_meter.compute_bill,
        (last_meter_obj,),
        None,
        None,
        dumps(readings),
        pack(openings),
        dumps(tariffs)
    )
    # [check]
    solution = transaction_to_solution(compute_bill_tx)
    tester(RUNS, "compute_bill [c]", smart_meter.contract.checkers['compute_bill'],
        solution['inputs'],
        solution['referenceInputs'],
        solution['parameters'],
        solution['outputs'],
        solution['returns'],
        solution['dependencies'],
    )
Example #30
0
from tester import tester
from tqdm import tqdm
import random
t = tester(['../_.bin'], ['../1017'])

random.seed(0)
pool = list(range(1, 101))
for i in tqdm(range(1000)):
    N = random.randint(1, 10)
    tc = [N] + random.sample(pool, N)
    equal, right, wrong = t.test(tc, isStr=False)
    if not equal:
        print('Case:')
        print(tc)
        print('Answer:')
        print(right)
        print('Output:')
        print(wrong)
Example #31
0
    def saveCfileAndCompile(self, C_txt, displayOutputPlace, currentHW, flag):
        import subprocess
        from subprocess import PIPE
        import sys
        import os
        import time
        from tester import tester
        self.__class__.pyDir = os.getcwd()
        self.__class__.helpDir = self.__class__.pyDir + r"/../helpers/hexes/"
        self.readPath()
        QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
        #print "current dir:", os.getcwd()
        #os.chdir("../helpers/hexes")
        #print "current dir:", os.getcwd()
        #commands:
        #note: aavrgcc commands are here, but Arduino Avrdude commands are in tester.py
        #LINUX
        print "HexMaker: mainWindowUI.projectName", self.__class__.projectName
        print "HexMaker: mainWindowUI.currentdir", self.__class__.currentFileDir
        if self.__class__.projectName == None:
            import main
            main.mainWindowUI().saveFileAs()
        if self.__class__.projectName == None:
            return
        filename = ntpath.basename(self.__class__.projectName)
        if currentHW == "Waltech" and self.opSys == "NIX":
            commandListo = r"../avr/bin/avr-gcc -x c -I. -g -mmcu=atmega32 -DF_CPU=4000000UL -Os -fpack-struct -fshort-enums -funsigned-bitfields -funsigned-char -Wall -std=gnu99 -Wa,-ahlms=" + filename + ".lst -c "
            commandOut = r"../avr/bin/avr-gcc  -I. -T " + self.__class__.pyDir + "/../helpers/avr/lib/ldscripts/avr5.x -Wl,-Map," + filename + ".out.map  -mmcu=atmega32 -lm -o " + filename + ".out "
            commandHex = r"../avr/bin/avr-objcopy -j .text -j .data -O ihex " + filename + ".out " + filename + ".hex"
            self.commandAvrDude = r"../avrdude  -C ../avrdude.conf -p m32 -P usb -c usbtiny -B5"

        if currentHW == "ArduinoUno" and self.opSys == "NIX":
            commandListo = r"../avr/bin/avr-gcc -x c -I. -g -mmcu=atmega328 -DF_CPU=16000000UL -Os -fpack-struct -fshort-enums -funsigned-bitfields -funsigned-char -Wall -std=gnu99 -Wa,-ahlms=" + filename + ".lst -c "
            commandOut = r"../avr/bin/avr-gcc  -I. -T " + self.__class__.pyDir + "/../helpers/avr/lib/ldscripts/avr5.x -Wl,-Map," + filename + ".out.map  -mmcu=atmega328 -lm -o " + filename + ".out "
            commandHex = r"../avr/bin/avr-objcopy -j .text -j .data -O ihex " + filename + ".out " + filename + ".hex"
            self.commandAvrDude = tester(self.opSys,
                                         currentHW).test1(displayOutputPlace)

        if currentHW == "ArduinoNano" and self.opSys == "NIX":
            commandListo = r"../avr/bin/avr-gcc -x c -I. -g -mmcu=atmega328 -DF_CPU=16000000UL -Os -fpack-struct -fshort-enums -funsigned-bitfields -funsigned-char -Wall -std=gnu99 -Wa,-ahlms=" + filename + ".lst -c "
            commandOut = r"../avr/bin/avr-gcc  -I. -T " + self.__class__.pyDir + "/../helpers/avr/lib/ldscripts/avr5.x -Wl,-Map," + filename + ".out.map  -mmcu=atmega328 -lm -o " + filename + ".out "
            commandHex = r"../avr/bin/avr-objcopy -j .text -j .data -O ihex " + filename + ".out " + filename + ".hex"
            self.commandAvrDude = tester(self.opSys,
                                         currentHW).test1(displayOutputPlace)

        if currentHW == "ArduinoMega" and self.opSys == "NIX":
            commandListo = r"../avr/bin/avr-gcc -x c -I. -g -mmcu=atmega2560 -DF_CPU=16000000UL -Os -fpack-struct -fshort-enums -funsigned-bitfields -funsigned-char -Wall -std=gnu99 -Wa,-ahlms=" + filename + ".lst -c "
            commandOut = r"../avr/bin/avr-gcc  -I. -T " + self.__class__.pyDir + "/../helpers/avr/lib/ldscripts/avr6.x -Wl,-Map," + filename + ".out.map  -mmcu=atmega2560 -lm -o " + filename + ".out "
            commandHex = r"../avr/bin/avr-objcopy -j .text -j .data -O ihex " + filename + ".out " + filename + ".hex"
            self.commandAvrDude = tester(self.opSys,
                                         currentHW).test1(displayOutputPlace)

        #MAC
        if currentHW == "Waltech" and self.opSys == "MAC":
            commandListo = r"avr-gcc -x c -I. -g -mmcu=atmega32 -DF_CPU=4000000UL -Os -fpack-struct -fshort-enums -funsigned-bitfields -funsigned-char -Wall -std=gnu99 -Wa,-ahlms=" + filename + ".lst -c "
            commandOut = r"avr-gcc  -I. -Wl,-Map," + filename + ".out.map  -mmcu=atmega32 -lm -o " + filename + ".out "
            commandHex = r"avr-objcopy -j .text -j .data -O ihex " + filename + ".out " + filename + ".hex"
            self.commandAvrDude = r"avrdude  -C ../avrdude.conf -p m32 -P usb -c usbtiny -B5"
        if currentHW == "ArduinoUno" and self.opSys == "MAC":
            commandListo = r"avr-gcc -x c -I. -g -mmcu=atmega328 -DF_CPU=16000000UL -Os -fpack-struct -fshort-enums -funsigned-bitfields -funsigned-char -Wall -std=gnu99 -Wa,-ahlms=" + filename + ".lst -c "
            commandOut = r"avr-gcc  -I. -Wl,-Map," + filename + ".out.map  -mmcu=atmega328 -lm -o " + filename + ".out "
            commandHex = r"avr-objcopy -j .text -j .data -O ihex " + filename + ".out " + filename + ".hex"
            self.commandAvrDude = tester(self.opSys,
                                         currentHW).test1(displayOutputPlace)

        if currentHW == "ArduinoNano" and self.opSys == "MAC":
            commandListo = r"avr-gcc -x c -I. -g -mmcu=atmega328 -DF_CPU=16000000UL -Os -fpack-struct -fshort-enums -funsigned-bitfields -funsigned-char -Wall -std=gnu99 -Wa,-ahlms=" + filename + ".lst -c "
            commandOut = r"avr-gcc  -I. -Wl,-Map," + filename + ".out.map  -mmcu=atmega328 -lm -o " + filename + ".out "
            commandHex = r"avr-objcopy -j .text -j .data -O ihex " + filename + ".out " + filename + ".hex"
            self.commandAvrDude = tester(self.opSys,
                                         currentHW).test1(displayOutputPlace)

        if currentHW == "ArduinoMega" and self.opSys == "MAC":
            commandListo = r"avr-gcc -x c -I. -g -mmcu=atmega2560 -DF_CPU=16000000UL -Os -fpack-struct -fshort-enums -funsigned-bitfields -funsigned-char -Wall -std=gnu99 -Wa,-ahlms=" + filename + ".lst -c "
            commandOut = r"avr-gcc  -I. -Wl,-Map," + filename + ".out.map  -mmcu=atmega2560 -lm -o " + filename + ".out "
            commandHex = r"avr-objcopy -j .text -j .data -O ihex " + filename + ".out " + filename + ".hex"
            self.commandAvrDude = tester(self.opSys,
                                         currentHW).test1(displayOutputPlace)

        #WINDOWS
        if currentHW == "Waltech" and self.opSys == "WIN":
            commandListo = r"..\\WinAVR\\bin\\avr-gcc.exe -x c -I. -g -mmcu=atmega32 -DF_CPU=4000000UL -Os -fpack-struct -fshort-enums -funsigned-bitfields -funsigned-char -Wall -std=gnu99 -Wa,-ahlms=" + filename + ".lst -c "
            commandOut = r"..\\WinAVR\\bin\\avr-gcc.exe  -I. -Wl,-Map," + filename + ".out.map  -mmcu=atmega32 -lm -o " + filename + ".out "
            commandHex = r"..\\WinAVR\\bin\\avr-objcopy.exe -j .text -j .data -O ihex " + filename + ".out " + filename + ".hex"
            self.commandAvrDude = r"..\\WinAVR\\bin\\avrdude.exe -p m32 -P usb -c usbtiny -B5"
        if currentHW == "ArduinoUno" and self.opSys == "WIN":
            commandListo = r"..\\WinAVR\\bin\\avr-gcc.exe -x c -I. -g -mmcu=atmega328 -DF_CPU=16000000UL -Os -fpack-struct -fshort-enums -funsigned-bitfields -funsigned-char -Wall -std=gnu99 -Wa,-ahlms=" + filename + ".lst -c "
            commandOut = r"..\\WinAVR\\bin\\avr-gcc.exe  -I. -Wl,-Map," + filename + ".out.map  -mmcu=atmega328 -lm -o " + filename + ".out "
            commandHex = r"..\\WinAVR\\bin\\avr-objcopy.exe -j .text -j .data -O ihex " + filename + ".out " + filename + ".hex"
            self.commandAvrDude = tester(self.opSys,
                                         currentHW).test1(displayOutputPlace)
        if currentHW == "ArduinoNano" and self.opSys == "WIN":
            commandListo = r"..\\WinAVR\\bin\\avr-gcc.exe -x c -I. -g -mmcu=atmega328 -DF_CPU=16000000UL -Os -fpack-struct -fshort-enums -funsigned-bitfields -funsigned-char -Wall -std=gnu99 -Wa,-ahlms=" + filename + ".lst -c "
            commandOut = r"..\\WinAVR\\bin\\avr-gcc.exe  -I. -Wl,-Map," + filename + ".out.map  -mmcu=atmega328 -lm -o " + filename + ".out "
            commandHex = r"..\\WinAVR\\bin\\avr-objcopy.exe -j .text -j .data -O ihex " + filename + ".out " + filename + ".hex"
            self.commandAvrDude = tester(self.opSys,
                                         currentHW).test1(displayOutputPlace)

        if currentHW == "ArduinoMega" and self.opSys == "WIN":
            commandListo = r"..\\WinAVR\\bin\\avr-gcc.exe -x c -I. -g -mmcu=atmega2560 -DF_CPU=16000000UL -Os -fpack-struct -fshort-enums -funsigned-bitfields -funsigned-char -Wall -std=gnu99 -Wa,-ahlms=" + filename + ".lst -c "
            commandOut = r"..\\WinAVR\\bin\\avr-gcc.exe  -I. -Wl,-Map," + filename + ".out.map  -mmcu=atmega2560 -lm -o " + filename + ".out "
            commandHex = r"..\\WinAVR\\bin\\avr-objcopy.exe -j .text -j .data -O ihex " + filename + ".out " + filename + ".hex"
            self.commandAvrDude = tester(self.opSys,
                                         currentHW).test1(displayOutputPlace)

#####run commands:
        print "current dir:", self.__class__.helpDir
        os.chdir(self.__class__.currentFileDir)
        print "current dir:", os.getcwd()
        f = open(filename + ".c", 'w')
        f.write(C_txt)
        f.close(
        )  # file is not immediately deleted because we used delete=False

        commandwfile = self.__class__.helpDir + commandListo
        commandwfile = commandwfile + filename + ".c"
        print commandwfile

        #p = subprocess.Popen(commandwfile, shell=True, cwd=r"./hexes")#linux
        p = subprocess.Popen(commandwfile, shell=True)
        while p.poll() is None:  # polls to see if the programming is done
            time.sleep(0.5)
        print "Process ended, ret code", p.returncode
        #displayOutputPlace.clear()
        if p.returncode != 0:
            displayOutputPlace.append("lst and o failed")
        if p.returncode == 0:
            displayOutputPlace.append(".lst and .o file generated")

        commandwfile = self.__class__.helpDir + commandOut + filename + ".o"
        print self.__class__.helpDir
        print commandwfile
        p = subprocess.Popen(commandwfile, shell=True)
        while p.poll() is None:  # polls to see if the programming is done
            time.sleep(0.5)
        #print "Process ended, ret code:", p.returncode
        if p.returncode != 0:
            displayOutputPlace.append("out file failed")
        if p.returncode == 0:
            displayOutputPlace.append("out file generated")

        commandwfile = self.__class__.helpDir + commandHex
        p = subprocess.Popen(commandwfile, shell=True)
        while p.poll() is None:  # polls to see if the programming is done
            time.sleep(0.5)
        #print "Process ended, ret code:", p.returncode
        if p.returncode != 0:
            displayOutputPlace.append("hex file failed")
        if p.returncode == 0:
            displayOutputPlace.append("hex file generated")
        QApplication.restoreOverrideCursor()
        os.chdir(self.__class__.pyDir)
        if flag == "B":
            self.burnHex(displayOutputPlace)
Example #32
0
from tester import tester
import random

t = tester(['../answer'], ['../_.bin'])

random.seed(0)
pool = ['A', 'B']
for i in range(10000):
    tc = ""
    tc += ''.join(random.choice(pool)
                  for i in range(random.randint(2, 6))) + '\n'
    tc += ''.join(random.choice(pool)
                  for i in range(random.randint(1, 3))) + '\n'
    equal, right, wrong = t.test(tc)
    if not equal:
        print('Case:')
        print(tc)
        print('Answer:')
        print(right)
        print('Output:')
        print(wrong)
def main():
    ## get contract and init pint
    sensor.contract._populate_empty_checkers()
    print "operation\t\tmean (s)\t\tsd (s)\t\truns"

    # ---------------------------------------------------------
    # get functions
    # ---------------------------------------------------------
    # init
    init_tx = sensor.init()
    token = init_tx['transaction']['outputs'][0]

    # create sensor
    create_sensor_tx = sensor.create_sensor(
        (token, ),
        None,
        None,
    )
    sensor_obj = create_sensor_tx['transaction']['outputs'][1]

    # add data
    add_data_tx = sensor.add_data((sensor_obj, ), None, [dumps([1, 2, 3])])

    # ---------------------------------------------------------
    # test create_sensor
    # ---------------------------------------------------------
    # [gen]
    tester(RUNS, "create_sensor [g]", sensor.create_sensor, (token, ), None,
           None)
    # [check]
    solution = transaction_to_solution(create_sensor_tx)
    tester(
        RUNS,
        "create_sensor [c]",
        sensor.contract.checkers['create_sensor'],
        solution['inputs'],
        solution['referenceInputs'],
        solution['parameters'],
        solution['outputs'],
        solution['returns'],
        solution['dependencies'],
    )

    # ---------------------------------------------------------
    # test add_data
    # ---------------------------------------------------------
    # [gen]
    tester(RUNS, "add_data [g]\t", sensor.add_data, (sensor_obj, ), None,
           [dumps([1, 2, 3])])
    # [gen]
    solution = transaction_to_solution(add_data_tx)
    tester(
        RUNS,
        "add_data [c]\t",
        sensor.contract.checkers['add_data'],
        solution['inputs'],
        solution['referenceInputs'],
        solution['parameters'],
        solution['outputs'],
        solution['returns'],
        solution['dependencies'],
    )