예제 #1
0
func Test03_Finish(t *testing.T) {
	// users
	var uid3 int
	uid3 = 333

	// a task : 1, 1, 5
	var taskId int
	taskId = 2

	testio := testio.New()
	nTM := New(testio)
	curNum, interval, remainedTime, err := nTM.CreateTask(uid3, taskId)
	if err != nil {
		t.Errorf("Fail CreateTask %d, %d, %d", curNum, interval, remainedTime)
	}
	log.Printf("TestFinish ----------- start(%d), interval(%d), remainTime(%d)", curNum, interval, remainedTime)

	time.Sleep(2 * time.Second)
	log.Printf(" 2초후")
	if true {
		log.Printf(" - 확인")
		nTM := New(testio)
		curNum, interval, remainedTime, err := nTM.CalcTask(uid3, taskId, 0)
		if err != nil {
			t.Errorf("Fail CreateTask %d, %d, %d", curNum, interval, remainedTime)
		}
		log.Printf(" - num 은 0, remainTime은 3이라야 함")
		if curNum != 0 || remainedTime != 3 {
			t.Errorf("Fail CreateTask %d, %d, %d", curNum, interval, remainedTime)
		}

		time.Sleep(2 * time.Second)
		log.Printf(" 2초후")
		log.Printf(" - 확인")
		nTM2 := New(testio)
		curNum, interval, remainedTime, err = nTM2.CalcTask(uid3, taskId, 0)
		if err != nil {
			t.Errorf("Fail CreateTask %d, %d, %d", curNum, interval, remainedTime)
		}
		log.Printf(" - num 은 0, remainTime은 1이라야 함")
		if curNum != 0 || remainedTime != 1 {
			t.Errorf("Fail CreateTask %d, %d, %d", curNum, interval, remainedTime)
		}

		time.Sleep(2 * time.Second)
		log.Printf(" 2초후")
		log.Printf(" - 확인")
		nTM3 := New(testio)
		curNum, interval, remainedTime, err = nTM3.CalcTask(uid3, taskId, 0)
		if err != nil {
			t.Errorf("Fail CreateTask %d, %d, %d", curNum, interval, remainedTime)
		}
		log.Printf(" - num 은 1, remainTime은 4이라야 함")
		if curNum != 1 || remainedTime != 4 {
			t.Errorf("Fail CreateTask %d, %d, %d", curNum, interval, remainedTime)
		}

		nTM = New(testio)
		err = nTM3.DeleteTask(uid3, taskId)
		if err != nil {
			t.Errorf("Fail DeleteTask %d, %d, %d, %s", curNum, interval, remainedTime, err)
		}

		time.Sleep(2 * time.Second)
		log.Printf(" 2초후")
		log.Printf(" - 확인")
		nTM = New(testio)
		curNum, interval, remainedTime, err = nTM.CalcTask(uid3, taskId, 0)
		if err == nil {
			t.Errorf("Fail CreateTask %d, %d, %d", curNum, interval, remainedTime)
		} else {
			fmt.Println(err)
		}
	}
}
예제 #2
0
func Test02_Calc(t *testing.T) {
	// users
	var uid1 int
	uid1 = 111

	// a task : 4, 4, 3
	var taskId int
	taskId = 1

	testio := testio.New()
	nTM := New(testio)
	curNum, interval, remainedTime, err := nTM.CreateTask(uid1, taskId)
	if err != nil {
		t.Errorf("Fail CreateTask %d, %d, %d", curNum, interval, remainedTime)
	}
	log.Printf("TestCalc ----------- start(%d), interval(%d), remainTime(%d)", curNum, interval, remainedTime)

	time.Sleep(2 * time.Second)
	if true {
		log.Printf(" - 하나 사용(-1)하고 task 시작")
		nTM := New(testio)
		curNum, interval, remainedTime, err := nTM.CalcTask(uid1, taskId, -1)
		if err != nil {
			t.Errorf("Fail CreateTask %d, %d, %d", curNum, interval, remainedTime)
		}
		log.Printf(" - num 은 3, remainTime은 3이라야 함")
		if curNum != 3 || remainedTime != 3 {
			t.Errorf("Fail CreateTask %d, %d, %d", curNum, interval, remainedTime)
		}

		time.Sleep(1 * time.Second)
		log.Printf(" 1초후")
		log.Printf(" -- TestCalc : 하나 사용(-1)")
		nTM2 := New(testio)
		curNum, interval, remainedTime, err = nTM2.CalcTask(uid1, taskId, -1)
		if err != nil {
			t.Errorf("Fail CreateTask %d, %d, %d", curNum, interval, remainedTime)
		}
		if curNum != 2 || remainedTime != 2 {
			t.Errorf("Fail CreateTask %d, %d, %d", curNum, interval, remainedTime)
		}

		time.Sleep(3 * time.Second)
		log.Printf(" 3초후")
		log.Printf(" -- TestCalc : 하나 사용(-1)")
		nTM3 := New(testio)
		curNum, interval, remainedTime, err = nTM3.CalcTask(uid1, taskId, -1)
		if err != nil {
			t.Errorf("Fail CreateTask %d, %d, %d", curNum, interval, remainedTime)
		}
		if curNum != 2 || remainedTime != 2 {
			t.Errorf("Fail CreateTask %d, %d, %d", curNum, interval, remainedTime)
		}

		time.Sleep(6 * time.Second)
		log.Printf(" 6초후")
		log.Printf(" -- TestCalc : 하나 사용(-1)")
		nTM = New(testio)
		curNum, interval, remainedTime, err = nTM.CalcTask(uid1, taskId, -1)
		if err != nil {
			t.Errorf("Fail CreateTask %d, %d, %d", curNum, interval, remainedTime)
		}
		if curNum != 3 || remainedTime != 3 {
			t.Errorf("Fail CreateTask %d, %d, %d", curNum, interval, remainedTime)
		}

		time.Sleep(2 * time.Second)
		log.Printf(" 2초후")
		log.Printf(" -- TestCalc : 3개 더함(3)")
		nTM = New(testio)
		curNum, interval, remainedTime, err = nTM.CalcTask(uid1, taskId, 3)
		if err != nil {
			t.Errorf("Fail CreateTask %d, %d, %d", curNum, interval, remainedTime)
		}
		if curNum != 6 || remainedTime != 1 {
			t.Errorf("Fail CreateTask %d, %d, %d", curNum, interval, remainedTime)
		}

		time.Sleep(2 * time.Second)
		log.Printf(" 23초후")
		log.Printf(" -- TestCalc : 하나 사용(-1)")
		nTM = New(testio)
		curNum, interval, remainedTime, err = nTM3.CalcTask(uid1, taskId, -1)
		if err != nil {
			t.Errorf("Fail CreateTask %d, %d, %d, %s", curNum, interval, remainedTime, err)
		}
		if curNum != 5 || remainedTime != 3 {
			t.Errorf("Fail CreateTask %d, %d, %d", curNum, interval, remainedTime)
		}

		nTM = New(testio)
		err = nTM3.DeleteTask(uid1, taskId)
		if err != nil {
			t.Errorf("Fail DeleteTask %d, %d, %d, %s", curNum, interval, remainedTime, err)
		}
	}
}