Algorithm
- 513. Find Bottom Left Tree Value - LeetCode
- 559. Maximum Depth of N-ary Tree - LeetCode
- 766. Toeplitz Matrix - LeetCode
- 893. Groups of Special-Equivalent Strings - LeetCode
- 696. Count Binary Substrings - LeetCode
- 165. Compare Version Numbers - LeetCode
Review
介绍 Go 语言对比 Python 的优点。
Tip
编写针对RestfullAPI的测试用例,以前测试都是写一个Controller,构造一个形似/test/user的映射进行测试
package com.imooc.demo.web.controller;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
/**
* Author: yangdc
* Date: 2018/8/26 4:13
*/
@RunWith(SpringRunner.class)
@SpringBootTest
public class UserControllerTest {
@Autowired
private WebApplicationContext context;
private MockMvc mockMvc;
@Before
public void setup() {
mockMvc = MockMvcBuilders.webAppContextSetup(context).build();
}
@Test
public void whenQuerySuccess() throws Exception {
mockMvc.perform(get("/user/query1")
.contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(status().isOk()) // 返回状态码为200
.andExpect(jsonPath("$.length()").value(3)); // 返回数据的集合长度是3
}
@Test
public void whenQuerySuccess2() throws Exception {
mockMvc.perform(get("/user/query2")
.param("username", "alex")
.contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(status().isOk())
.andExpect(jsonPath("$.length()").value(3));
}
@Test
public void whenQuerySuccess3() throws Exception {
mockMvc.perform(get("/user/query3")
.param("username", "alex")
.param("age", "18")
.param("ageTo", "22")
.param("size", "15")
.param("page", "3")
.param("sort", "age,desc")
.contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(status().isOk()) // 返回状态码为200
.andExpect(jsonPath("$.length()").value(3)); // 返回数据的集合长度是3
}
}