@@ -481,4 +481,108 @@ var _ = Describe("Glucose", func() {
481481 ),
482482 )
483483 })
484+
485+ Context ("Classify" , func () {
486+ var MmolL = pointer .FromAny (dataBloodGlucose .MmolL )
487+ var MgdL = pointer .FromAny (dataBloodGlucose .MgdL )
488+
489+ checkClassification := func (value float64 , expected glucose.Classification ) {
490+ GinkgoHelper ()
491+ datum := dataTypesBloodGlucoseTest .NewGlucose (MmolL )
492+ datum .Value = pointer .FromAny (value )
493+ got , err := glucose .TidepoolADAClassificationThresholdsMmolL .Classify (datum )
494+ Expect (err ).To (Succeed ())
495+ Expect (got ).To (Equal (expected ))
496+ }
497+
498+ It ("classifies 2.9 as very low" , func () {
499+ checkClassification (2.9 , "very low" )
500+ })
501+
502+ It ("classifies 3.0 as low" , func () {
503+ checkClassification (3.0 , "low" )
504+ })
505+
506+ It ("classifies 3.8 as low" , func () {
507+ checkClassification (3.8 , "low" )
508+ })
509+
510+ It ("classifies 3.9 as on target" , func () {
511+ checkClassification (3.9 , "on target" )
512+ })
513+
514+ It ("classifies 10.0 as on target" , func () {
515+ checkClassification (10.0 , "on target" )
516+ })
517+
518+ It ("classifies 10.1 as high" , func () {
519+ checkClassification (10.1 , "high" )
520+ })
521+
522+ It ("classifies 13.9 as high" , func () {
523+ checkClassification (13.9 , "high" )
524+ })
525+
526+ It ("classifies 14.0 as very high" , func () {
527+ checkClassification (14.0 , "very high" )
528+ })
529+
530+ It ("classifies 19.4 as very high" , func () {
531+ checkClassification (19.4 , "very high" )
532+ })
533+
534+ It ("classifies 19.5 as extremely high" , func () {
535+ checkClassification (19.5 , "extremely high" )
536+ })
537+
538+ When ("its classification depends on rounding" , func () {
539+ It ("classifies 2.95 as low" , func () {
540+ checkClassification (2.95 , "low" )
541+ })
542+
543+ It ("classifies 3.85 as low" , func () {
544+ checkClassification (3.85 , "low" )
545+ })
546+
547+ It ("classifies 10.05 as on target" , func () {
548+ checkClassification (10.05 , "on target" )
549+ })
550+ })
551+
552+ When ("it doesn't recognize the units" , func () {
553+ It ("returns an error" , func () {
554+ badUnits := "blah"
555+ datum := dataTypesBloodGlucoseTest .NewGlucose (& badUnits )
556+ datum .Value = pointer .FromAny (5.0 )
557+ _ , err := glucose .TidepoolADAClassificationThresholdsMmolL .Classify (datum )
558+ Expect (err ).To (MatchError (ContainSubstring ("unable to normalize: unhandled units" )))
559+ })
560+ })
561+
562+ It ("can handle values in mg/dL" , func () {
563+ datum := dataTypesBloodGlucoseTest .NewGlucose (MgdL )
564+ datum .Value = pointer .FromAny (100.0 )
565+ got , err := glucose .TidepoolADAClassificationThresholdsMmolL .Classify (datum )
566+ Expect (err ).To (Succeed ())
567+ Expect (string (got )).To (Equal ("on target" ))
568+ })
569+
570+ When ("it's value is nil" , func () {
571+ It ("returns an error" , func () {
572+ datum := dataTypesBloodGlucoseTest .NewGlucose (MmolL )
573+ datum .Value = nil
574+ _ , err := glucose .TidepoolADAClassificationThresholdsMmolL .Classify (datum )
575+ Expect (err ).To (MatchError (ContainSubstring ("unable to normalize: unhandled value" )))
576+ })
577+ })
578+
579+ When ("it's units are nil" , func () {
580+ It ("returns an error" , func () {
581+ datum := dataTypesBloodGlucoseTest .NewGlucose (nil )
582+ datum .Value = pointer .FromAny (5.0 )
583+ _ , err := glucose .TidepoolADAClassificationThresholdsMmolL .Classify (datum )
584+ Expect (err ).To (MatchError (ContainSubstring ("unable to normalize: unhandled units" )))
585+ })
586+ })
587+ })
484588})
0 commit comments