From 185ecdc96c9022920cdf367deb8cc933bf6da6d7 Mon Sep 17 00:00:00 2001 From: johnwalley Date: Thu, 3 Aug 2017 16:21:13 +0100 Subject: [PATCH] Fix up ad_format tests --- package.json | 2 +- src/util.js | 18 +++++++++++++++++- test/bumps-test.js | 5 +++-- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 26a2ed1..dee2106 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "d3-bumps-chart", - "version": "0.6.2", + "version": "0.6.3", "description": "Draw bumps charts.", "keywords": [ "d3", diff --git a/src/util.js b/src/util.js index 6d29217..deaa372 100644 --- a/src/util.js +++ b/src/util.js @@ -1323,10 +1323,25 @@ export function write_ad(event) { let divStr = ` ${div.length} ${genderStr} Div ${roman[index]}\n`; div.forEach((crew, crewIndex) => { + let position = crewIndex; + let currentDivision = index; divStr += `${padEnd(renderName(crew, event.set), 25)}`; + for (let day = 0; day < event.days; day++) { - divStr += padStart(event.move[day][index][crewIndex], 4); + divStr += padStart(event.move[day][currentDivision][position], 4); + position -= event.move[day][currentDivision][position]; + + if (position < 0) { + currentDivision -= 1; + position += event.divisions[currentDivision].length; + } + + if (position >= event.divisions[currentDivision].length) { + position -= event.divisions[currentDivision].length; + currentDivision += 1; + } } + divStr += '\n'; }); @@ -1336,3 +1351,4 @@ export function write_ad(event) { return ret; } + diff --git a/test/bumps-test.js b/test/bumps-test.js index 9c3f16a..5d04306 100644 --- a/test/bumps-test.js +++ b/test/bumps-test.js @@ -577,7 +577,7 @@ St John's III -4 -4 -1 -1 St Hilda's 1 1 1 1 Mansfield II -1 -1 -1 1 Wolfson III 2 1 1 1 - 13 *Men's Div VI + 13 Men's Div VI Exeter II -1 2 1 1 Merton II 3 1 1 1 L.M.H. II 0 1 2 1 @@ -590,7 +590,8 @@ Oriel III -2 -2 1 1 Christ Church III 0 0 0 0 S.E.H. III 2 1 1 1 Corpus Christi II 0 1 0 -2 -Balliol IV 0 1 -1 1`; +Balliol IV 0 1 -1 1 +`; var expected = data; var actual = bumps.write_ad(bumps.read_ad(data));