allergies.test.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import { Allergies } from './allergies'
  2. describe('allergicTo', () => {
  3. it('no allergies means not allergic', () => {
  4. const allergies = new Allergies(0)
  5. expect(allergies.allergicTo('peanuts')).toBeFalsy()
  6. expect(allergies.allergicTo('cats')).toBeFalsy()
  7. expect(allergies.allergicTo('strawberries')).toBeFalsy()
  8. })
  9. xit('is allergic to eggs', () => {
  10. const allergies = new Allergies(1)
  11. expect(allergies.allergicTo('eggs')).toBeTruthy()
  12. })
  13. xit('allergic to eggs in addition to other stuff', () => {
  14. const allergies = new Allergies(5)
  15. expect(allergies.allergicTo('eggs')).toBeTruthy()
  16. expect(allergies.allergicTo('shellfish')).toBeTruthy()
  17. expect(allergies.allergicTo('strawberries')).toBeFalsy()
  18. })
  19. })
  20. describe('list', () => {
  21. xit('no allergies at all', () => {
  22. const allergies = new Allergies(0)
  23. const expected: string[] = []
  24. expect(allergies.list()).toEqual(expected)
  25. })
  26. xit('allergic to just eggs', () => {
  27. const allergies = new Allergies(1)
  28. const expected = ['eggs']
  29. expect(allergies.list()).toEqual(expected)
  30. })
  31. xit('allergic to just peanuts', () => {
  32. const allergies = new Allergies(2)
  33. const expected = ['peanuts']
  34. expect(allergies.list()).toEqual(expected)
  35. })
  36. xit('allergic to just strawberries', () => {
  37. const allergies = new Allergies(8)
  38. const expected = ['strawberries']
  39. expect(allergies.list()).toEqual(expected)
  40. })
  41. xit('allergic to eggs and peanuts', () => {
  42. const allergies = new Allergies(3)
  43. const expected = ['eggs', 'peanuts']
  44. expect(allergies.list()).toEqual(expected)
  45. })
  46. xit('allergic to more than eggs but not peanuts', () => {
  47. const allergies = new Allergies(5)
  48. const expected = ['eggs', 'shellfish']
  49. expect(allergies.list()).toEqual(expected)
  50. })
  51. xit('allergic to lots of stuff', () => {
  52. const allergies = new Allergies(248)
  53. const expected = ['strawberries', 'tomatoes', 'chocolate', 'pollen', 'cats']
  54. expect(allergies.list()).toEqual(expected)
  55. })
  56. xit('allergic to everything', () => {
  57. const allergies = new Allergies(255)
  58. const expected = [
  59. 'eggs',
  60. 'peanuts',
  61. 'shellfish',
  62. 'strawberries',
  63. 'tomatoes',
  64. 'chocolate',
  65. 'pollen',
  66. 'cats',
  67. ]
  68. expect(allergies.list()).toEqual(expected)
  69. })
  70. xit('ignore non allergen score parts', () => {
  71. const allergies = new Allergies(509)
  72. const expected = [
  73. 'eggs',
  74. 'shellfish',
  75. 'strawberries',
  76. 'tomatoes',
  77. 'chocolate',
  78. 'pollen',
  79. 'cats',
  80. ]
  81. expect(allergies.list()).toEqual(expected)
  82. })
  83. xit('ignore non allergen score parts, without highest valid score', () => {
  84. const allergies = new Allergies(257)
  85. const expected = ['eggs']
  86. expect(allergies.list()).toEqual(expected)
  87. })
  88. })