2021-01-29 06:31:58 -05:00
|
|
|
//
|
|
|
|
// FILE: unit_test_001.cpp
|
|
|
|
// AUTHOR: Rob Tillaart
|
|
|
|
// VERSION: 0.1.0
|
|
|
|
// DATE: 2020-12-08
|
|
|
|
// PURPOSE: unit tests for the AD520X digital potentiometers
|
|
|
|
// https://github.com/RobTillaart/AD520X
|
|
|
|
// https://github.com/Arduino-CI/arduino_ci/blob/master/REFERENCE.md
|
|
|
|
//
|
|
|
|
|
|
|
|
// supported assertions
|
|
|
|
// ----------------------------
|
|
|
|
// assertEqual(expected, actual)
|
|
|
|
// assertNotEqual(expected, actual)
|
|
|
|
// assertLess(expected, actual)
|
|
|
|
// assertMore(expected, actual)
|
|
|
|
// assertLessOrEqual(expected, actual)
|
|
|
|
// assertMoreOrEqual(expected, actual)
|
|
|
|
// assertTrue(actual)
|
|
|
|
// assertFalse(actual)
|
|
|
|
// assertNull(actual)
|
|
|
|
|
2021-08-22 04:47:15 -04:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
#include <ArduinoUnitTests.h>
|
|
|
|
|
|
|
|
#include "Arduino.h"
|
|
|
|
#include "AD520X.h"
|
|
|
|
|
|
|
|
|
|
|
|
unittest_setup()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-08-22 04:47:15 -04:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
unittest_teardown()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-08-22 04:47:15 -04:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
unittest(test_begin)
|
|
|
|
{
|
2021-08-22 04:47:15 -04:00
|
|
|
fprintf(stderr, "AD520X_LIB_VERSION:\t%s", AD520X_LIB_VERSION);
|
2021-01-29 06:31:58 -05:00
|
|
|
AD5204 pot = AD5204(10, 12, 13); // HW SPI
|
|
|
|
pot.begin();
|
|
|
|
assertEqual(128, pot.getValue(0));
|
|
|
|
|
|
|
|
pot.begin(42);
|
|
|
|
assertEqual(42, pot.getValue(0));
|
|
|
|
}
|
|
|
|
|
2021-08-22 04:47:15 -04:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
unittest(test_setValue)
|
|
|
|
{
|
|
|
|
AD5206 pot = AD5206(10, 12, 13); // HW SPI
|
|
|
|
pot.begin();
|
|
|
|
assertEqual(128, pot.getValue(0));
|
|
|
|
|
|
|
|
for (int i = 0; i < pot.pmCount(); i++)
|
|
|
|
{
|
|
|
|
pot.setValue(i, 35);
|
|
|
|
assertEqual(35, pot.getValue(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
pot.setAll(42);
|
|
|
|
for (int i = 0; i < pot.pmCount(); i++)
|
|
|
|
{
|
|
|
|
assertEqual(42, pot.getValue(i));
|
|
|
|
}
|
2021-10-16 14:58:54 -04:00
|
|
|
|
|
|
|
assertFalse(pot.setValue(6, 10));
|
|
|
|
|
|
|
|
AD8400 p8400 = AD8400(10, 12, 13);
|
|
|
|
assertFalse(p8400.setValue(1, 117));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
unittest(test_setPercentage)
|
|
|
|
{
|
|
|
|
AD5206 pot = AD5206(10, 12, 13); // HW SPI
|
|
|
|
pot.begin();
|
|
|
|
assertEqualFloat(50, pot.getPercentage(0), 0.5);
|
|
|
|
|
|
|
|
for (int i = 0; i < pot.pmCount(); i++)
|
|
|
|
{
|
|
|
|
pot.setPercentage(i, 35);
|
|
|
|
assertEqualFloat(35, pot.getPercentage(i), 0.5);
|
|
|
|
}
|
2021-01-29 06:31:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
unittest(test_reset)
|
|
|
|
{
|
|
|
|
AD5204 pot = AD5204(10, 12, 13); // HW SPI
|
|
|
|
pot.begin();
|
|
|
|
assertEqual(128, pot.getValue(0));
|
|
|
|
|
|
|
|
pot.reset(35);
|
2021-08-22 04:47:15 -04:00
|
|
|
for (int i = 0; i < pot.pmCount(); i++)
|
|
|
|
{
|
|
|
|
assertEqual(35, pot.getValue(i));
|
|
|
|
}
|
2021-01-29 06:31:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
unittest(test_power)
|
|
|
|
{
|
|
|
|
AD5204 pot = AD5204(10, 12, 13); // HW SPI
|
|
|
|
pot.begin(213);
|
|
|
|
assertEqual(213, pot.getValue(0));
|
|
|
|
assertTrue(pot.isPowerOn());
|
|
|
|
|
|
|
|
pot.powerOff();
|
|
|
|
assertFalse(pot.isPowerOn());
|
|
|
|
delay(100);
|
|
|
|
|
|
|
|
pot.powerOn();
|
|
|
|
assertTrue(pot.isPowerOn());
|
|
|
|
delay(100);
|
|
|
|
|
|
|
|
for (int i = 0; i < pot.pmCount(); i++)
|
|
|
|
{
|
|
|
|
assertEqual(213, pot.getValue(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
unittest(test_pm_count)
|
|
|
|
{
|
|
|
|
AD5204 pot1 = AD5204(10, 12, 13); // HW SPI
|
|
|
|
pot1.begin();
|
|
|
|
assertEqual(4, pot1.pmCount());
|
|
|
|
|
|
|
|
AD5206 pot2 = AD5206(10, 12, 13); // HW SPI
|
|
|
|
pot2.begin();
|
|
|
|
assertEqual(6, pot2.pmCount());
|
|
|
|
|
|
|
|
AD8403 pot3 = AD8403(10, 12, 13); // HW SPI
|
|
|
|
pot3.begin();
|
|
|
|
assertEqual(4, pot3.pmCount());
|
|
|
|
|
|
|
|
AD8402 pot4 = AD8402(10, 12, 13); // HW SPI
|
|
|
|
pot4.begin();
|
|
|
|
assertEqual(2, pot4.pmCount());
|
|
|
|
|
|
|
|
AD8400 pot5 = AD8400(10, 12, 13); // HW SPI
|
|
|
|
pot5.begin();
|
|
|
|
assertEqual(1, pot5.pmCount());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
unittest_main()
|
|
|
|
|
|
|
|
// --------
|