tdd for coding practices - by zhifu ge
TRANSCRIPT
–Robert C. Marin
“You should plan on working 60 hours per week. The first 40 are for your employer. The
remaining 20 are for yourself. ”
require “minitest/autorun”
def MyTest < Minitest::Test def test_meaning_of
life = Life.new assert_equal 42, meaning_of(life); endend
The problem• The definition of equilibrium index
• Sum of 0 elements are 0
• Worst-case time complexity is O(N)
Index(i) 0 1 2 3 4 5 6 7 8
a -1 3 -4 5 1 -6 2 1
prefix_sum 0 -1 2 -2 3 4 -2 0 1
the sum of a[p] to a[q] is prefix_sum[q + 1] - prefix_sum[p]