Advertisement
kstoyanov

06. RGB to Hex

Oct 26th, 2020
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. describe("rgbToHexColor(red, green, blue)", function () {
  2.    describe("Nominal cases(valid input)", function () {
  3.        it("should return #FF9EAA for (255, 158, 170)", function () {
  4.            expect(rgbToHexColor(255, 158, 170)).to.be.equal("#FF9EAA");
  5.        });
  6.        it("should return #0C0D0E for (12, 13, 14)", function () {
  7.            expect(rgbToHexColor(12, 13, 14)).to.be.equal("#0C0D0E");
  8.        });
  9.        it("should return #000000 for (0, 0, 0)", function () {
  10.            expect(rgbToHexColor(0, 0, 0)).to.be.equal("#000000");
  11.        });
  12.        it("should return #FFFFFF for (255, 255, 255)", function () {
  13.            expect(rgbToHexColor(255, 255, 255)).to.be.equal("#FFFFFF");
  14.        });
  15.    });
  16.  
  17.     describe("Special cases(invalid input", function () {
  18.         it("should return undefined for (-1,0,0)", function () {
  19.             expect(rgbToHexColor(-1, 0, 0)).to.be.equal(undefined);
  20.         });
  21.         it("should return undefined for (0,-1,0)", function () {
  22.             expect(rgbToHexColor(0, -1, 0)).to.be.equal(undefined);
  23.         });
  24.         it("should return undefined for (0,0,-1)", function () {
  25.             expect(rgbToHexColor(0, 0, -1)).to.be.equal(undefined);
  26.         });
  27.         it("should return undefined for (256,0,0)", function () {
  28.             expect(rgbToHexColor(256, 0, 0)).to.be.equal(undefined);
  29.         });
  30.         it("should return undefined for (0,256,0)", function () {
  31.             expect(rgbToHexColor(0, 256, 0)).to.be.equal(undefined);
  32.         });
  33.         it("should return undefined for (0,0,256)", function () {
  34.             expect(rgbToHexColor(0, 0, 256)).to.be.equal(undefined);
  35.         });
  36.         it("should return undefined for (3.14,0,0)", function () {
  37.             expect(rgbToHexColor(3.14, 0, 0)).to.be.equal(undefined);
  38.         });
  39.         it("should return undefined for (0,3.14,0)", function () {
  40.             expect(rgbToHexColor(0, 3.14, 0)).to.be.equal(undefined);
  41.         });
  42.         it("should return undefined for (0,0,3.14)", function () {
  43.             expect(rgbToHexColor(0, 0, 3.14)).to.be.equal(undefined);
  44.         });
  45.         it('should return undefined for ("5", [3], {8:9})', function () {
  46.             expect(rgbToHexColor("5", [3], {8:9})).to.be.equal(undefined);
  47.         });
  48.         it("should return undefined for empty input", function () {
  49.             expect(rgbToHexColor()).to.be.equal(undefined);
  50.         });
  51.     });
  52. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement