Question: Please help me get code that passes through this test file. My file is named assignment 2 but I can't add it here due to
Please help me get code that passes through this test file. My file is named assignment but I can't add it here due to the character limit I asked a similar question recently which has my code. This is the test file cannot be edited that I need to run my code through:
from Assignment import WeatherSimulation
import numpy as np
import sys
import pylint as pl
# printdirassignment
print
printTesting Assignment DV
print
#Check Python version
if sysversioninfo :
print
Your python version info is:sysversioninfo
sysexitPython version should be equal or bigger than
else:
printf
Your python version is correct sysversioninfo
def checkformalitiestransitions holdingtime:
ITERATINGROUNDS
# Check creating WeatherSimulation
try:
weathersim WeatherSimulationtransitions holdingtime
except:
printERROR Error in create WeatherSimulation object.
sysexitNOK
# Check methods
# setholdingtimeinstate', 'currentstate', 'currentstatestayinghours', 'currentstateremaininghours', 'nextstate', 'iterable', 'simulate'
methods getstates', 'setstate', 'currentstate', 'currentstateremaininghours', 'nextstate', 'iterable', 'simulate'
if not allmaplambda x: hasattrweathersim, x and callablegetattrweathersim, x methods:
printERROR Not all methods has been implemented.
sysexitNOK
# Check iterables
printf
Testing iterating for ITERATINGROUNDS rounds:
try:
simiter weathersim.iterable
for i in rangeITERATINGROUNDS:
printnextsimiter
except:
printERROR Problem in iterating!
sysexitNOK
# Check Pylint score
# Decision: not at this stage
def checkexceptionwrongtransitions, holdingtime:
printf
Check exception handling'
try:
weathersim WeatherSimulationwrongtransitions, holdingtime
except RuntimeError as err:
printfException raised correctly with details: err
result True
except :
printfException raised but not with RuntimeError object'
result False
else:
result False
return result
def checkholdingtimestransitions holdingtime:
printf
Check holding times'
NUMCHANGES
weathersim WeatherSimulationtransitions holdingtime
for i in rangeNUMCHANGES:
laststate weathersim.currentstate
hd holdingtimelaststate
for j in rangehd:
if weathersim.currentstate laststate:
printfError: State laststate changed before holding time hd to weathersim.currentstate
return False
weathersim.nextstate
return True
def runtesttransitions holdingtime, avg, tolerance:
STATES sunny 'cloudy', 'rainy', 'snowy'
HOURS
weathersim WeatherSimulationtransitions holdingtime
# Test simulation
printf
Testing simulation function for HOURS hours:
freq weathersim.simulateHOURS
printfSimulation resulted in listzipSTATESfreq
# Check if the percentages adds up to
if roundnpsumfreq:
sysexitERROR Summarization percentages do not add up to
diff listmaplambda x: roundabsxx zipfreqavg
if anylistmaplambda x: xx zipdifftolerance:
printfSome of your results are out of the acceptable range.
printfHigher range: listmaplambda x: roundxx zipavgtolerance
printfYour result: freq
printfLower range: listmaplambda x: roundxx zipavgtolerance
else:
printfResults are in the acceptable range.
printfHigher range: listmaplambda x: roundxx zipavgtolerance
printfYour result: freq
printfLower range: listmaplambda x: roundxx zipavgtolerance
return True
transitions
'sunny':sunny: 'cloudy': 'rainy': 'snowy':
'cloudy':sunny: 'cloudy': 'rainy': 'snowy':
'rainy':sunny: 'cloudy': 'rainy': 'snowy':
'snowy':sunny: 'cloudy': 'rainy': 'snowy':
wrongtransitions
'sunny':sunny: 'cloudy': 'rainy': 'snowy':
'cloudy':sunny: 'cloudy': 'rainy': 'snowy':
'rainy':sunny: 'cloudy': 'rainy': 'snowy':
'snowy':sunny: 'cloudy': 'rainy': 'snowy':
holdingtime sunny: 'cloudy': 'rainy': 'snowy':
# No holding time The rest of the test code is in the photo uploaded with the assignment pics
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
