-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add fixtures for resistor-color (#24)
Fixtures for #13
- Loading branch information
1 parent
413419e
commit 4c22541
Showing
510 changed files
with
5,472 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export const COLORS = [ | ||
"black", | ||
"brown", | ||
"red", | ||
"orange", | ||
"yellow", | ||
"green", | ||
"blue", | ||
"violet", | ||
"grey", | ||
"white" | ||
]; | ||
|
||
export const colorCode = color => COLORS.indexOf(color); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { colorCode, COLORS } from './resistor-color' | ||
|
||
describe('ResistorColor', () => { | ||
describe('Color codes', () => { | ||
test('Black', () => { | ||
expect(colorCode("black")).toEqual(0) | ||
}) | ||
|
||
test('White', () => { | ||
expect(colorCode("white")).toEqual(9) | ||
}) | ||
|
||
test('Orange', () => { | ||
expect(colorCode("orange")).toEqual(3) | ||
}) | ||
}) | ||
|
||
test('Colors', () => { | ||
expect(COLORS).toEqual(["black","brown","red","orange","yellow","green","blue","violet","grey","white"]) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export const COLORS = ["black", "brown", "red", "orange", "yellow", "green", "blue", "violet", "grey", "white"]; | ||
|
||
export const colorCode = color => COLORS.indexOf(color); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const color_dict = { | ||
'black': 0, | ||
'brown': 1, | ||
'red': 2, | ||
'orange': 3, | ||
'yellow': 4, | ||
'green': 5, | ||
'blue': 6, | ||
'violet': 7, | ||
'grey': 8, | ||
'white': 9 | ||
} | ||
export const colorCode = (COLOR) => { | ||
return color_dict[COLOR] | ||
} | ||
export const COLORS = Object.keys(color_dict) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const COLORS = ["black", "brown", "red", "orange", "yellow", "green", "blue", "violet", "grey", "white"], | ||
colorCode = (color) => COLORS.indexOf(color); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export let colorCode = (band) => COLORS.indexOf(band); | ||
|
||
export const COLORS = ["black","brown","red","orange","yellow","green","blue","violet","grey","white"]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const COLORS = ["black", "brown", "red", "orange", "yellow", "green", "blue", "violet", "grey", "white"]; | ||
|
||
export function colorCode(color) { | ||
return COLORS.indexOf(color); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const COLORS = [ | ||
'black', | ||
'brown', | ||
'red', | ||
'orange', | ||
'yellow', | ||
'green', | ||
'blue', | ||
'violet', | ||
'grey', | ||
'white' | ||
] | ||
|
||
function colorCode (color) { | ||
return COLORS.indexOf(color.toLowerCase()) | ||
} | ||
|
||
export { colorCode, COLORS } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const COLORS = ["black","brown","red","orange","yellow","green","blue","violet","grey","white"]; | ||
|
||
export const colorCode = (color) => { | ||
for(let i = 0; i < COLORS.length; i++){ if (COLORS[i] == color){ return i } } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* eslint-disable no-empty */ | ||
/* eslint-disable no-console */ | ||
/* eslint-disable no-unused-vars */ | ||
export const COLORS = ["black","brown","red","orange","yellow", | ||
"green","blue","violet","grey","white"]; | ||
|
||
export const colorCode = (color) => COLORS.indexOf(color); | ||
|
||
|
||
|
||
|
||
//console.log(COLORS); | ||
console.log(colorCode("white")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const COLORS = ["black","brown","red","orange","yellow","green","blue","violet","grey","white"] | ||
|
||
export function colorCode (color) { | ||
return COLORS.indexOf(color) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const COLORS = ["black","brown","red","orange","yellow","green","blue","violet","grey","white"]; | ||
|
||
export const colorCode = color => COLORS.indexOf(color); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const COLORS = ["black","brown","red","orange","yellow","green","blue","violet","grey","white"] | ||
|
||
export const colorCode = color => COLORS.indexOf(color.toLowerCase()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export const COLORS = ["black","brown","red","orange","yellow","green","blue","violet","grey","white"] | ||
export const colorCode = (color) => { | ||
for (let i = 0; i < COLORS.length; i++) { | ||
if (COLORS[i] === color) { | ||
return i | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
export const colorCode = (color) => { | ||
for(var i = 0; i < COLORS.length; i++) { | ||
if (COLORS[i] == color) { | ||
return i; | ||
} | ||
} | ||
} | ||
|
||
export const COLORS = ["black", "brown", "red", "orange", "yellow", "green", "blue", "violet", "grey", "white"]; | ||
|
||
|
||
|
||
/** | ||
* | ||
Resistors have color coded bands, where each color maps to a number. The first 2 bands of a resistor have a simple encoding scheme: each color maps to a single number. | ||
These colors are encoded as follows: | ||
Black: 0 | ||
Brown: 1 | ||
Red: 2 | ||
Orange: 3 | ||
Yellow: 4 | ||
Green: 5 | ||
Blue: 6 | ||
Violet: 7 | ||
Grey: 8 | ||
White: 9 | ||
Mnemonics map the colors to the numbers, that, when stored as an array, happen to map to their index in the array: Better Be Right Or Your Great Big Values Go Wrong. | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export const COLORS = | ||
[ | ||
'black', | ||
'brown', | ||
'red', | ||
'orange', | ||
'yellow', | ||
'green', | ||
'blue', | ||
'violet', | ||
'grey', | ||
'white' | ||
]; | ||
|
||
export const colorCode = (color) => COLORS.indexOf(color); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const colorCode = (code) => COLORS.indexOf(code); | ||
const COLORS = ["black","brown","red","orange","yellow","green","blue","violet","grey","white"]; | ||
export { colorCode, COLORS }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const COLORS = [ | ||
"black", | ||
"brown", | ||
"red", | ||
"orange", | ||
"yellow", | ||
"green", | ||
"blue", | ||
"violet", | ||
"grey", | ||
"white" | ||
]; | ||
|
||
const colorCode = color => COLORS.indexOf(color); | ||
|
||
export { colorCode, COLORS }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export const COLORS = [ | ||
'black', 'brown', 'red', 'orange', 'yellow', 'green', | ||
'blue', 'violet', 'grey', 'white', | ||
] | ||
|
||
export const colorCode = color => COLORS.indexOf(color) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export const COLORS = ["black", "brown", "red", "orange", "yellow", "green", "blue", "violet", "grey", "white"]; | ||
|
||
export function colorCode(color) { | ||
let resistorColor = color.toLowerCase(); | ||
return COLORS.indexOf(resistorColor); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* Simple mapping resistors colors to numbers | ||
*/ | ||
|
||
// Defining colors in order | ||
export const COLORS = ["black", "brown", "red", "orange", "yellow", "green", | ||
"blue", "violet", "grey", "white"]; | ||
|
||
// Function to return index of a specific color | ||
export function colorCode(color) { | ||
return COLORS.indexOf(color); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
export let COLORS = [ | ||
"black", | ||
"brown", | ||
"red", | ||
"orange", | ||
"yellow", | ||
"green", | ||
"blue", | ||
"violet", | ||
"grey", | ||
"white" | ||
]; | ||
|
||
/** | ||
* Returns index of `color` in COLORS array | ||
* @param {String} color | ||
*/ | ||
export let colorCode = | ||
color => COLORS.findIndex(item => color === item); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const colorCode = (color) => COLORS.indexOf(color); | ||
|
||
export const COLORS = ["black", "brown", "red", "orange", "yellow", "green", "blue", "violet", "grey", "white"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const COLORS = [ | ||
'black', | ||
'brown', | ||
'red', | ||
'orange', | ||
'yellow', | ||
'green', | ||
'blue', | ||
'violet', | ||
'grey', | ||
'white' | ||
]; | ||
|
||
const colorCode = color => COLORS.findIndex(element => element === color); | ||
|
||
export { COLORS, colorCode }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export const COLORS = ["black","brown","red","orange","yellow","green","blue","violet","grey","white"] | ||
export const colorCode = (color,colors=["black","brown","red","orange","yellow","green","blue","violet","grey","white"]) => { | ||
return colors.indexOf(color) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const COLORS = ["black","brown","red","orange","yellow","green","blue","violet","grey","white"]; | ||
|
||
export function colorCode(color) { | ||
return COLORS.indexOf(color); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export let COLORS = ["black","brown","red","orange","yellow","green","blue","violet","grey","white"]; | ||
export function colorCode(color) { | ||
for(let i = 0; i<COLORS.length; i++){ | ||
if(color === COLORS[i]) | ||
return i; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const COLORS = ["black", "brown", "red", "orange", "yellow", "green", "blue", "violet", "grey", "white"] | ||
const colorCode = (color)=> COLORS.indexOf(color) | ||
|
||
export { | ||
COLORS, | ||
colorCode | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const COLORS = ["black","brown","red","orange","yellow","green","blue","violet","grey","white"]; | ||
|
||
export const colorCode = (color) => COLORS.indexOf(color); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const COLORS = ['black', 'brown', 'red', 'orange', 'yellow', 'green', 'blue', 'violet', 'grey', 'white']; | ||
|
||
export const colorCode = (color) => { | ||
return COLORS.indexOf(color); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const colorMap = { | ||
"black": 0, | ||
"brown": 1, | ||
"red": 2, | ||
"orange": 3, | ||
"yellow": 4, | ||
"green": 5, | ||
"blue": 6, | ||
"violet": 7, | ||
"grey": 8, | ||
"white": 9 | ||
} | ||
|
||
const colorCode = (color) => { | ||
return colorMap[color]; | ||
} | ||
|
||
const COLORS = Object.keys(colorMap) | ||
|
||
export { | ||
colorCode, | ||
COLORS | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export const COLORS = ["black","brown","red","orange","yellow","green","blue","violet","grey","white"]; | ||
|
||
export const colorCode = color => COLORS.indexOf(color.toLowerCase()); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
export const COLORS = [ | ||
'black', | ||
'brown', | ||
'red', | ||
'orange', | ||
'yellow', | ||
'green', | ||
'blue', | ||
'violet', | ||
'grey', | ||
'white' | ||
]; | ||
|
||
export const CODES = COLORS.reduce((accum, color, i) => { | ||
accum[color] = i; | ||
return accum; | ||
}, {}); | ||
|
||
export const colorCode = (color) => { | ||
return CODES[color]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const COLORS = [ "black", "brown", "red", "orange", "yellow", "green", "blue", "violet", "grey", "white" ]; | ||
|
||
export const colorCode = function(colorName) { | ||
return COLORS.indexOf(colorName); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const COLORS = ['black','brown','red','orange','yellow','green','blue','violet','grey','white'] | ||
export const colorCode = (color, list = COLORS ) => list.indexOf(color) > -1 ? list.indexOf(color) : null; |
Oops, something went wrong.