github.com/maypok86/otter@v1.2.1/internal/core/task_test.go (about) 1 // Copyright (c) 2023 Alexey Mayshev. All rights reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package core 16 17 import ( 18 "testing" 19 20 "github.com/maypok86/otter/internal/generated/node" 21 ) 22 23 func TestTask(t *testing.T) { 24 nm := node.NewManager[int, int](node.Config{ 25 WithExpiration: true, 26 WithCost: true, 27 }) 28 n := nm.Create(1, 2, 6, 4) 29 oldNode := nm.Create(1, 3, 8, 6) 30 31 addTask := newAddTask(n) 32 if addTask.node() != n || !addTask.isAdd() { 33 t.Fatalf("not valid add task %+v", addTask) 34 } 35 36 deleteTask := newDeleteTask(n) 37 if deleteTask.node() != n || !deleteTask.isDelete() { 38 t.Fatalf("not valid delete task %+v", deleteTask) 39 } 40 41 updateTask := newUpdateTask(n, oldNode) 42 if updateTask.node() != n || !updateTask.isUpdate() || updateTask.oldNode() != oldNode { 43 t.Fatalf("not valid update task %+v", updateTask) 44 } 45 46 clearTask := newClearTask[int, int]() 47 if clearTask.node() != nil || !clearTask.isClear() { 48 t.Fatalf("not valid clear task %+v", clearTask) 49 } 50 51 closeTask := newCloseTask[int, int]() 52 if closeTask.node() != nil || !closeTask.isClose() { 53 t.Fatalf("not valid close task %+v", closeTask) 54 } 55 }