initial commit
This commit is contained in:
26
c/resistor-color-duo/src/resistor_color_duo.c
Normal file
26
c/resistor-color-duo/src/resistor_color_duo.c
Normal file
@@ -0,0 +1,26 @@
|
||||
#include "resistor_color_duo.h"
|
||||
#if defined UNIT_TEST || defined DEBUG
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
resistor_band_t color_code(resistor_band_t *colors)
|
||||
{
|
||||
resistor_band_t c1=*colors, c2=*(colors+1);
|
||||
|
||||
return c1>=BLACK && c1<=WHITE && c2>=BLACK && c2<=WHITE? c1*10+c2: ERROR;
|
||||
}
|
||||
|
||||
#ifdef UNIT_TEST
|
||||
int main(int ac, char **av)
|
||||
{
|
||||
int arg=1;
|
||||
resistor_band_t i[2];
|
||||
|
||||
for (; arg<ac-1; ++arg, ++arg) {
|
||||
*i=atoi(av[arg]);
|
||||
*(i+1)=atoi(av[arg+1]);
|
||||
printf("color(%d, %d)=%d\n", i[0], i[1], color_code(i));
|
||||
}
|
||||
}
|
||||
#endif
|
25
c/resistor-color-duo/src/resistor_color_duo.h
Normal file
25
c/resistor-color-duo/src/resistor_color_duo.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#ifndef RESISTOR_COLOR_DUO_H
|
||||
#define RESISTOR_COLOR_DUO_H
|
||||
|
||||
typedef enum {
|
||||
BLACK=0,
|
||||
BROWN,
|
||||
RED,
|
||||
ORANGE,
|
||||
YELLOW,
|
||||
GREEN,
|
||||
BLUE,
|
||||
VIOLET,
|
||||
GREY,
|
||||
WHITE,
|
||||
ERROR=-1,
|
||||
} resistor_band_t;
|
||||
|
||||
extern resistor_band_t color_code(resistor_band_t *);
|
||||
|
||||
#ifdef TESTALL
|
||||
#undef TEST_IGNORE
|
||||
#define TEST_IGNORE() {}
|
||||
#endif
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user