Top Banner
TDD for Coding Practices A demo by Zhifu Ge
19

TDD for Coding Practices - by Zhifu Ge

Jan 11, 2017

Download

Software

ottawaruby
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: TDD for Coding Practices - by Zhifu Ge

TDD for Coding PracticesA demo by Zhifu Ge

Page 2: TDD for Coding Practices - by Zhifu Ge

Why Practice?

Page 3: TDD for Coding Practices - by Zhifu Ge

Because all professionals do

Page 4: TDD for Coding Practices - by Zhifu Ge
Page 5: TDD for Coding Practices - by Zhifu Ge

working is not practicing

Page 6: TDD for Coding Practices - by Zhifu Ge

–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. ”

Page 7: TDD for Coding Practices - by Zhifu Ge

Why TDD

Page 8: TDD for Coding Practices - by Zhifu Ge

It gives me the peace of mind

Page 9: TDD for Coding Practices - by Zhifu Ge

How to TDD

Page 10: TDD for Coding Practices - by Zhifu Ge

• write enough test for it to fail • write enough code for the test to pass • repeat as necessary

Page 11: TDD for Coding Practices - by Zhifu Ge

Why Minitest

Page 12: TDD for Coding Practices - by Zhifu Ge

it’s simple and does everything the other guys do

Page 13: TDD for Coding Practices - by Zhifu Ge

How to Minitest

Page 14: TDD for Coding Practices - by Zhifu Ge

require “minitest/autorun”

def MyTest < Minitest::Test def test_meaning_of

life = Life.new assert_equal 42, meaning_of(life); endend

Page 15: TDD for Coding Practices - by Zhifu Ge

The problem• The definition of equilibrium index

• Sum of 0 elements are 0

• Worst-case time complexity is O(N)

Page 16: TDD for Coding Practices - by Zhifu Ge

Prefix Sum

Page 17: TDD for Coding Practices - by Zhifu Ge

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]

Page 18: TDD for Coding Practices - by Zhifu Ge

The Demo