Skip to content

Commit

Permalink
Pseudotest Dioder.SetChannelInteger()
Browse files Browse the repository at this point in the history
Removed the range-check, as an unit8 cannot go under 0 and over 255.
  • Loading branch information
jannickfahlbusch committed Dec 14, 2016
1 parent 6d0662c commit 071a42f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
14 changes: 2 additions & 12 deletions dioder.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package dioder

import (
"bufio"
"errors"
"image/color"
"os"
"strconv"
Expand Down Expand Up @@ -130,19 +129,10 @@ func (d *Dioder) SetColor(channel int32, value float64) error {

//SetChannelInteger check if the value is in the correct range and convert it to float64
func (d *Dioder) SetChannelInteger(value uint8, channel int32) error {
if value > 255 {
return errors.New("Value can not be over 255")
}

if value < 0 {
return errors.New("Value can not be under 0")
}

floatval := float64(value) / 255.0

d.SetColor(channel, float64(floatval))

return nil
err := d.SetColor(channel, float64(floatval))
return err
}

//Release releases all used pins, so that they can be used in other applications
Expand Down
9 changes: 9 additions & 0 deletions dioder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,12 @@ func TestDioderTurnOn(t *testing.T) {
t.Errorf("Value for blue is wrong. Expected 0, got %d", d.ColorConfiguration.B)
}
}

func TestDioder_SetChannelInteger(t *testing.T) {
d := New(pinConfiguration, piBlasterFile)

err := d.SetChannelInteger(255, 1)
if err != nil {
t.Errorf("Error: %s", err)
}
}

0 comments on commit 071a42f

Please sign in to comment.