Preserving numerical meaning during replacement

An energy module accepts one or more intervals, each containing a finite nonnegative power PiP_i in watts and a finite positive duration Δti\Delta t_i in seconds. Its public contract returns total energy in joules:


E=∑iPiΔti.E=\sum_i P_i\Delta t_i.


A replacement keeps the same inputs and output type but calculates the ordinary arithmetic mean of the powers and multiplies it by the total duration. It passes tests with one interval and tests with equal interval durations.


A proposed additional test supplies 60 W60\ \text{W} for 10 s10\ \text{s}, followed by 180 W180\ \text{W} for 30 s30\ \text{s}. Which review decision best tests and preserves the documented contract?


Power is 60 watts for the first 10 seconds and 180 watts for the following 30 seconds.


Choose an answer

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Modular Programming Questions: