Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Testing and Improving Code
00:00
5 left

Testing and Improving Code

HardPython

Problem

Keysight's calibration team runs a Go service that validates a batch of readings coming off automated RF test benches before a chip lot is signed off. Here is the current implementation.

package calibration

import "fmt"
import "os"
import "strconv"
import "sync"

type Reading struct {
	InstrumentID string
	RawValue     string
	Tolerance    float64
}

func ValidateCalibrationBatch(readings []Reading, logPath string) map[string]bool {
	results := map[string]bool{}
	var wg sync.WaitGroup

	logFile, _ := os.Open(logPath)

	for i := 0; i < len(readings)-1; i++ {
		r := readings[i]
		wg.Add(1)
		go func() {
			defer wg.Done()
			value, _ := strconv.ParseFloat(r.RawValue, 64)
			results[r.InstrumentID] = value == r.Tolerance
		}()
	}

	wg.Wait()
	fmt.Fprintf(logFile, "validated %d instruments
", len(results))
	return results
}

Walk through this code and describe how you would test it and what you would improve. You're answering in free text, not editing the file, so explain what you'd change and why.

Discuss correctness, concurrency safety, resource and error handling, numeric comparison, duplicate instrument IDs, and test isolation. A useful behavioral model is a deterministic validator that processes every reading and returns the final status for each instrument.

Constraints

  • readings is a list of reading objects
  • Each reading contains instrument_id, raw_value, and tolerance
  • raw_value is a decimal string or malformed input
  • Duplicate instrument IDs use last-write-wins semantics
  • Invalid numeric input produces false

Function Signature

def validate_calibration_batch(readings):
Interviewer

Your question is Testing and Improving Code. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
Sign up free to run your codeLog inLn 2
Run your code to see test output here.