Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test.js 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. var SunCalc = require('./suncalc'),
  2. t = require('tap');
  3. function near(val1, val2, margin) {
  4. return Math.abs(val1 - val2) < (margin || 1E-15);
  5. }
  6. var date = new Date('2013-03-05UTC'),
  7. lat = 50.5,
  8. lng = 30.5;
  9. var testTimes = {
  10. solarNoon: '2013-03-05T10:10:57Z',
  11. nadir: '2013-03-04T22:10:57Z',
  12. sunrise: '2013-03-05T04:34:56Z',
  13. sunset: '2013-03-05T15:46:57Z',
  14. sunriseEnd: '2013-03-05T04:38:19Z',
  15. sunsetStart: '2013-03-05T15:43:34Z',
  16. dawn: '2013-03-05T04:02:17Z',
  17. dusk: '2013-03-05T16:19:36Z',
  18. nauticalDawn: '2013-03-05T03:24:31Z',
  19. nauticalDusk: '2013-03-05T16:57:22Z',
  20. nightEnd: '2013-03-05T02:46:17Z',
  21. night: '2013-03-05T17:35:36Z',
  22. goldenHourEnd: '2013-03-05T05:19:01Z',
  23. goldenHour: '2013-03-05T15:02:52Z'
  24. };
  25. t.test('getPosition returns azimuth and altitude for the given time and location', function (t) {
  26. var sunPos = SunCalc.getPosition(date, lat, lng);
  27. t.ok(near(sunPos.azimuth, -2.5003175907168385), 'azimuth');
  28. t.ok(near(sunPos.altitude, -0.7000406838781611), 'altitude');
  29. t.end();
  30. });
  31. t.test('getTimes returns sun phases for the given date and location', function (t) {
  32. var times = SunCalc.getTimes(date, lat, lng);
  33. for (var i in testTimes) {
  34. t.equal(new Date(testTimes[i]).toUTCString(), times[i].toUTCString(), i);
  35. }
  36. t.end();
  37. });
  38. t.test('getMoonPosition returns moon position data given time and location', function (t) {
  39. var moonPos = SunCalc.getMoonPosition(date, lat, lng);
  40. t.ok(near(moonPos.azimuth, -0.9783999522438226), 'azimuth');
  41. t.ok(near(moonPos.altitude, 0.014551482243892251), 'altitude');
  42. t.ok(near(moonPos.distance, 364121.37256256194), 'distance');
  43. t.end();
  44. });
  45. t.test('getMoonIllumination returns fraction and angle of moon\'s illuminated limb and phase', function (t) {
  46. var moonIllum = SunCalc.getMoonIllumination(date);
  47. t.ok(near(moonIllum.fraction, 0.4848068202456373), 'fraction');
  48. t.ok(near(moonIllum.phase, 0.7548368838538762), 'phase');
  49. t.ok(near(moonIllum.angle, 1.6732942678578346), 'angle');
  50. t.end();
  51. });
  52. t.test('getMoonTimes returns moon rise and set times', function (t) {
  53. var moonTimes = SunCalc.getMoonTimes(new Date('2013-03-04UTC'), lat, lng, true);
  54. t.equal(moonTimes.rise.toUTCString(), 'Mon, 04 Mar 2013 23:54:29 GMT');
  55. t.equal(moonTimes.set.toUTCString(), 'Mon, 04 Mar 2013 07:47:58 GMT');
  56. t.end();
  57. });