Examples of unittests used in my small programme | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Examples of unittests used in my small programme

Hey, I have tough time working on this. I need to add 3 unittest's to my code, nothing too complicated, just need to use unittest and check something in this code, like is it possible to count NPV (so it's checking if there are 9 values in my .csv file? not sure how does testing work...) ? I have no idea how to implement it to my code and I can't understand examples from the internet. Would love to see them on my code, maybe then I could finally get it. Can anyone of you help me with this? My code is counting NPV from .csv file (here's a link to it: https://www.justbeamit.com/w8iuk) Code: --- from pandas import read_csv from numpy import npv def counting_npv(): for index, row in fund.iterrows(): row = row.tolist() np_list.append(npv(row[1], row[2:])) prjN = row[0] print("NPV for project no. {}: PLN {:,.2f}".format(prjN, np_list[index])) fund = read_csv("inwestycje.csv", delimiter=',') funds = [tuple(x) for x in fund.values] np_list = [] counting_npv() maxnpv = (np_list.index(max(np_list)))+1 print ("Best project: {}.".format(maxnpv)) --- Thank you in advance! Cheers.

26th Jan 2019, 6:53 PM
Konik
Konik - avatar
1 Answer
+ 2
The way I'd do it is create 3 files with answers you know. Create a function to process one of those files and verify your counting is doing the correct thing for it's content. Repeat this for the other 2 files. You could write the fixed data of the file in those functions. You could use: os.path.isfile("inwestycje.csv") to see if a user file exists. If yes, process it. If no, run your test functions.
29th Jan 2019, 12:35 AM
John Wells
John Wells - avatar