1. 程式人生 > 實用技巧 >RESTful日#7:使用NUnit和Moq框架在WebAPI中進行單元測試和整合測試(第一部分)

RESTful日#7:使用NUnit和Moq框架在WebAPI中進行單元測試和整合測試(第一部分)

import java.util.Stack;

public class CQueue {
    Stack<Integer> stack1 = new Stack<>();
    Stack<Integer> stack2 = new Stack<>();
    public CQueue() {

    }

    public void appendTail(int value) {
        stack1.push(value);
    }

    public int deleteHead() {
        
if(stack1.isEmpty()) return -1; while(!stack1.isEmpty()){ stack2.push(stack1.pop()); } int val = stack2.pop(); while (!stack2.isEmpty()){ stack1.push(stack2.pop()); } return val; } }

import java.util.Stack;

public class
CQueue { Stack<Integer> stack1 = new Stack<>(); Stack<Integer> stack2 = new Stack<>(); public CQueue() { } public void appendTail(int value) { stack1.push(value); } public int deleteHead() { if(stack1.isEmpty() && stack2.isEmpty()) return
-1; if(stack2.isEmpty()) { while (!stack1.isEmpty()) { stack2.push(stack1.pop()); } return stack2.pop(); }else{ return stack2.pop(); } } }

不用刪除一個元素之後,就立刻將stack2中的元素復原到stack1中。