Debian Codegraph @

tools/antithesis-go-instrumentor/scanners/coverage/instrumentor/testdata/runtime_edges/branches/program.go

raw
1 // Command branches exercises if / else-if chains and && / || short-circuit
2 // operators. It is side-effect free (no I/O beyond argv) and fully argv-driven,
3 // so every instrumented edge is reachable by some input:
4 //
5 // program -5 // ||: left operand true, right short-circuited
6 // program 200 // ||: right operand evaluated
7 // program 4 // &&: both operands evaluated (even, nonzero)
8 // program 0 // &&: right operand evaluated and false
9 // program 3 // &&: left operand false, right short-circuited
10 package main
11
12 import (
13 "os"
14 "strconv"
15 )
16
17 // sink keeps the results observable-free work from being elided without any
18 // external side effect.
19 var sink string
20
21 func classify(n int) string {
22 if n < 0 || n > 100 {
23 return "out-of-range"
24 }
25 if n%2 == 0 && n != 0 {
26 return "even"
27 }
28 return "odd-or-zero"
29 }
30
31 func main() {
32 n, _ := strconv.Atoi(os.Args[1])
33 sink = classify(n)
34 }