Automated testing on push in Git - Time & Space Complexity
When code is pushed to a repository, automated tests run to check for errors. We want to understand how the time taken to run these tests changes as the number of tests grows.
How does adding more tests affect the total time before feedback?
Analyze the time complexity of this git hook running automated tests on push.
#!/bin/sh
# pre-push hook
echo "Running automated tests..."
for test in tests/*.sh; do
sh "$test" || exit 1
done
echo "All tests passed!"
This script runs each test script in the tests folder one by one before allowing the push.
- Primary operation: Running each test script once.
- How many times: Once per test script in the tests directory.
As the number of test scripts increases, the total time grows proportionally because each test runs separately.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | Runs 10 tests |
| 100 | Runs 100 tests |
| 1000 | Runs 1000 tests |
Pattern observation: Doubling the number of tests roughly doubles the total time.
Time Complexity: O(n)
This means the total time grows linearly with the number of tests run on each push.
[X] Wrong: "Running more tests won't affect push time much because they run fast."
[OK] Correct: Even fast tests add up when many run one after another, so total time grows with test count.
Understanding how test count affects push time helps you design better workflows and explain trade-offs clearly in real projects.
"What if tests ran in parallel instead of one by one? How would the time complexity change?"