• 数据生成python脚本


    下面是项目结构:

    --data 存放数据的文件夹
    
    --main.cpp 题目的正确数据
    
    --prodData.py  生成输入输出数据脚本
    
    --test.cpp    测试代码
    
    --testData.py  测试代码是否正确脚本

    prodData.py

    #-*- coding:utf-8 -*-
    
    '''
    @auther: Starry
    @file: prodData.py
    @time: 2018/1/17 15:47
    '''
    
    import random
    import os
    
    DATASIZE = 10
    
    '''
    每个数据一组数据
    '''
    for i in range(DATASIZE):
        print('The %dth set of test data is being produced.' % i)
        with open('./data/test'+str(i)+'.in','w',encoding='utf-8') as f:
            N = random.randint(1, 100000)
            M = random.randint(1, 100000)
            f.write(str(N)+' '+str(M)+'
    ')
            for j in range(M):
                a = random.randint(1,10000)
                b = random.randint(1,10000)
                c = random.randint(1,200)
                f.write(str(a)+' '+str(b)+' '+str(c)+'
    ')
        with open('./data/test'+str(i)+'.out','w',encoding='utf-8') as f:
            pass
        os.system('g++ -std=c++11 main.cpp -o main')
        os.system('main < data\test'+str(i)+'.in >> data\test'+str(i)+'.out')
    
    '''
    多组数据 0 结束
    '''
    
    # for i in range(DATASIZE):
    #     print('The %dth set of test data is being produced.'%i)
    #     with open('./data/test'+str(i)+'.in','w',encoding='utf-8') as f:
    #         while True:
    #             N = random.randint(-70,1000)
    #             if N <= 0:
    #                 f.write(str(0)+'
    ')
    #                 break
    #             f.write(str(N)+'
    ')
    #             for j in range(N):
    #                 a = random.randint(1,50)
    #                 f.write(str(a)+' ')
    #             f.write('
    ')
    #             M = random.randint(0,1000)
    #             f.write(str(M)+'
    ')
    #     with open('./data/test'+str(i)+'.out','w',encoding='utf-8') as f:
    #         pass
    #     os.system('g++ -std=c++11 main.cpp -o main')
    #     os.system('main < data\test'+str(i)+'.in >> data\test'+str(i)+'.out')
    
    
    '''
    多组数据
    '''
    
    # for i in range(DATASIZE):
    #     print('The %dth set of test data is being produced.' % i)
    #     with open('./data/test'+str(i)+'.in','w',encoding='utf-8') as f:
    #         for j in range(random.randint(1,20)):
    #             N = random.randint(1, 100)
    #             M = random.randint(1, 100)
    #             K = random.randint(1, 100)
    #             S = random.randint(1, 100)
    #             f.write(str(N)+' '+str(M)+' '+str(K)+' '+str(S)+'
    ')
    #             for k in range(K):
    #                 a = random.randint(1,20)
    #                 b = random.randint(1,20)
    #                 f.write(str(a)+' '+str(b)+'
    ')
    #     with open('./data/test'+str(i)+'.out','w',encoding='utf-8') as f:
    #         pass
    #     os.system('g++ -std=c++11 main.cpp -o main')
    #     os.system('main < data\test'+str(i)+'.in >> data\test'+str(i)+'.out')

    testData.py

    #-*- coding:utf-8 -*-
    
    '''
    @auther: Starry
    @file: testData.py
    @time: 2018/1/17 15:46
    '''
    
    import os
    
    DATASIZE = 10
    
    os.system('g++ test.cpp -o test')
    WA = False
    for i in range(DATASIZE):
        print('The %dth set of data is being tested.'%i)
        os.system('test < data\test'+str(i)+'.in > te.out')
        flag = os.system('fc data\test'+str(i)+'.out te.out > nul')
        if flag != 0:
            print('Wrong answer on test'+str(i)+'.in!!!')
            WA = True
    
    if not WA:
        print("Accepted!!!")
  • 相关阅读:
    20191317王鹏宇第四章学习笔记
    20191317王鹏宇2.3.1测试
    树莓派openeuler安装openssl及其实践
    树莓派实验指导第三章实验
    树莓派openeuler的安装以及ukui桌面的安装并安装远程桌面vnc
    20191317王鹏宇鲲鹏服务器测试
    反汇编测试
    信息安全系统设计与实现第八周:《Unix/Linux系统编程》第五章学习笔记
    团队作业三
    信息安全系统设计与实现第七周:《Unix/Linux系统编程》第四章学习笔记
  • 原文地址:https://www.cnblogs.com/xingkongyihao/p/8316096.html
Copyright © 2020-2023  润新知