| 
									
										
										
										
											2023-09-07 11:00:16 -05:00
										 |  |  | package utils | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-08 15:24:40 -05:00
										 |  |  | import ( | 
					
						
							|  |  |  | 	"errors" | 
					
						
							|  |  |  | 	"fmt" | 
					
						
							|  |  |  | 	"testing" | 
					
						
							|  |  |  | ) | 
					
						
							| 
									
										
										
										
											2023-09-07 11:00:16 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-08 15:24:40 -05:00
										 |  |  | func hmsTest(t *testing.T, time string, expected float64, expecterr error) { | 
					
						
							|  |  |  | 	found, err := HourMinSecToSeconds(time) | 
					
						
							|  |  |  | 	var expecterrmsg, errmsg string | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		errmsg = err.Error() | 
					
						
							| 
									
										
										
										
											2023-09-07 11:00:16 -05:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2023-09-08 15:24:40 -05:00
										 |  |  | 	if expecterr != nil { | 
					
						
							|  |  |  | 		expecterrmsg = expecterr.Error() | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if found != expected || errmsg != expecterrmsg { | 
					
						
							|  |  |  | 		t.Fatalf(`HourMinSecToSeconds("%s") = %v, %v, want %v, %v`, time, found, err, expected, expecterr) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func TestTwoManyParts(t *testing.T) { | 
					
						
							|  |  |  | 	val := "2:3:4:5:6" | 
					
						
							|  |  |  | 	err := fmt.Sprintf("Can't parse %s. Must be in HH:MM:SS format", val) | 
					
						
							|  |  |  | 	hmsTest(t, val, 0, errors.New(err)) | 
					
						
							| 
									
										
										
										
											2023-09-07 11:00:16 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func TestJustSeconds(t *testing.T) { | 
					
						
							| 
									
										
										
										
											2023-09-08 15:24:40 -05:00
										 |  |  | 	hmsTest(t, "4.23", 4.23, nil) | 
					
						
							| 
									
										
										
										
											2023-09-07 11:00:16 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func TestMinuteSeconds(t *testing.T) { | 
					
						
							| 
									
										
										
										
											2023-09-08 15:24:40 -05:00
										 |  |  | 	hmsTest(t, "2:3.45", 123.45, nil) | 
					
						
							| 
									
										
										
										
											2023-09-07 11:00:16 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func TestHourMinuteSeconds(t *testing.T) { | 
					
						
							| 
									
										
										
										
											2023-09-08 15:24:40 -05:00
										 |  |  | 	hmsTest(t, "3:5:12.43", 11112.43, nil) | 
					
						
							| 
									
										
										
										
											2023-09-07 11:00:16 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func TestLeadingZeros(t *testing.T) { | 
					
						
							| 
									
										
										
										
											2023-09-08 15:24:40 -05:00
										 |  |  | 	hmsTest(t, "03:05:02.43", 11102.43, nil) | 
					
						
							| 
									
										
										
										
											2023-09-07 11:00:16 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func TestWholeSecond(t *testing.T) { | 
					
						
							| 
									
										
										
										
											2023-09-08 15:24:40 -05:00
										 |  |  | 	hmsTest(t, "4:2", 242, nil) | 
					
						
							| 
									
										
										
										
											2023-09-07 11:00:16 -05:00
										 |  |  | } |