github.com/iDigitalFlame/xmt@v0.5.4/c2/cfg/workhours_test.go (about) 1 // Copyright (C) 2020 - 2023 iDigitalFlame 2 // 3 // This program is free software: you can redistribute it and/or modify 4 // it under the terms of the GNU General Public License as published by 5 // the Free Software Foundation, either version 3 of the License, or 6 // any later version. 7 // 8 // This program is distributed in the hope that it will be useful, 9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 // GNU General Public License for more details. 12 // 13 // You should have received a copy of the GNU General Public License 14 // along with this program. If not, see <https://www.gnu.org/licenses/>. 15 // 16 17 package cfg 18 19 import ( 20 "testing" 21 "time" 22 ) 23 24 func TestWorkhours(t *testing.T) { 25 var ( 26 w = time.Now().Weekday() 27 h = &WorkHours{Days: (127) &^ (1 << uint(w))} 28 ) 29 if d := h.Work(); d == 0 { 30 t.Fatalf("TestWorkhours(): Work time should not be zero!") 31 } 32 n := byte('R') 33 if w != time.Thursday { 34 n = w.String()[0] 35 } 36 c := make([]rune, 0, 7) 37 for i, v := range "SMTWRFS" { 38 if byte(v) != n { 39 c = append(c, v) 40 continue 41 } 42 if n == 'S' && ((w != time.Sunday && i == 0) || (w != time.Saturday && i > 0)) { 43 c = append(c, 'S') 44 } 45 } 46 if r := string(c); r != h.String() { 47 t.Fatalf(`TestWorkhours(): Work String() should be "%s" not "%s"!`, r, h.String()) 48 } 49 }