工作以來一直需要對新開發的功能或 React 元件在上版前做測試,以保證所有組件與函式能如預期的運作。雖然感覺還沒完全摸透這方面的知識,但仍想紀錄一下自己到目前為止的理解以供日後參考。

Unit Test 單元測試

單元測試就是在程式專案 (project) 中對小單位的程式碼進行測試。聽起來好像很抽象,因為所謂的小單位程式碼測試項目是需要自行定義的。以現任公司的作法為例,測試的標的通常是函式、React 元件或整個頁面;而測試進行的項目,除了常見的輸入輸出正確性測試外,也可以測元件有沒有被正確渲染、特定事件有沒有被觸發、特定的變數值是否合乎預期等等。

Read more »

上個禮拜趁著公司兩週一度的 Mental Health Day,跑了一趟 DOL (Department of Licensing) 並順利完成駕照申請。趁著還記憶猶新的時候,記錄一下當時換發華盛頓州駕照的經驗,希望能幫助到有同樣需求的朋友。

背景

台灣與美加兩國數州的州政府簽有駕照互惠協議,其中光美國就有 35 州,另還包含一些特區與自治邦。根據各州的規定不同,有些州允許用台灣駕照免試換發當地駕照,有些則會再要求筆試。而華盛頓州是其中一個允許用台灣駕照免試換照的州。因此若你有台灣駕照且駕駛紀錄良好,你可以考慮拿台灣駕照換發這邊的駕照,省時又省力。

Read more »

Description

Question: Given a non-empty binary tree, find the maximum path sum.

For this problem, a path is defined as any sequence of nodes from some starting node to any node in the tree along the parent-child connections. The path must contain at least one node and does not need to go through the root.

Leetcode link: 124. Binary Tree Maximum Path Sum

Read more »

Description

Question: Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.

(i.e., [0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2]).

You are given a target value to search. If found in the array return its index, otherwise return -1.

You may assume no duplicate exists in the array.

Your algorithm’s runtime complexity must be in the order of O(log n).

Leetcode link: 33. Search in Rotated Sorted Array

Read more »

Description

Question: Given inorder and postorder traversal of a tree, construct the binary tree.

You may assume that duplicates do not exist in the tree.

For example, given:

1
2
inorder = [9,3,15,20,7]
postorder = [9,15,7,20,3]

Return the following binary tree:

1
2
3
4
5
  3
/ \
9 20
/ \
15 7

Leetcode link: 106. Construct Binary Tree from Inorder and Postorder Traversal

105. Construct Binary Tree from Inorder and Postorder Traversal (Related)

Read more »

Description

Question: A sequence of number is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same.

A zero-indexed array A consisting of N numbers is given. A slice of that array is any pair of integers (P, Q) such that 0 <= P < Q < N.

A slice (P, Q) of array A is called arithmetic if the sequence:
A[P], A[p + 1], …, A[Q - 1], A[Q] is arithmetic. In particular, this means that P + 1 < Q.

The function should return the number of arithmetic slices in the array A.

Leetcode link: 413. Arithmetic Slices

Read more »

Description

Question: Given a 2D board and a word, find if the word exists in the grid. The word can be constructed from letters of sequentially adjacent cell, where “adjacent” cells are those horizontally or vertically neighboring. The same letter cell may not be used more than once.

Leetcode link: 79. Word Search

Read more »

Description

Question: Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine if s can be segmented into a space-separated sequence of one or more dictionary words.

Note: The same word in the dictionary may be reused multiple times in the segmentation.
You may assume the dictionary does not contain duplicate words.

Leetcode link: 139. Word Break

Read more »