mirror of https://github.com/sveltejs/svelte
parent
f45160c53d
commit
639c2fb9ea
@ -0,0 +1,26 @@
|
||||
export default {
|
||||
html: `
|
||||
<div>12 120 70, 30+4=34</div>
|
||||
<div>35 350 120, 50+7=57</div>
|
||||
<div>48 480 140, 60+8=68</div>
|
||||
`,
|
||||
async test({ component, target, assert }) {
|
||||
component.boxes = [];
|
||||
assert.htmlEqual(target.innerHTML, `
|
||||
<div>10 * 2 = 20</div>
|
||||
`);
|
||||
|
||||
component.constant = 35;
|
||||
assert.htmlEqual(target.innerHTML, `
|
||||
<div>35 * 2 = 70</div>
|
||||
`);
|
||||
|
||||
component.boxes = [
|
||||
{width: 3, height: 4}
|
||||
];
|
||||
|
||||
assert.htmlEqual(target.innerHTML, `
|
||||
<div>12 420 245, 105+4=109</div>
|
||||
`);
|
||||
}
|
||||
};
|
||||
@ -0,0 +1,22 @@
|
||||
<script>
|
||||
export let boxes = [
|
||||
{width: 3, height: 4},
|
||||
{width: 5, height: 7},
|
||||
{width: 6, height: 8},
|
||||
];
|
||||
export let constant = 10;
|
||||
|
||||
function calculate(width, height, constant) {
|
||||
return { area: width * height, volume: width * height * constant };
|
||||
}
|
||||
</script>
|
||||
|
||||
{#each boxes as box}
|
||||
{@const {area, volume} = calculate(box.width, box.height, constant)}
|
||||
{@const perimeter = (box.width + box.height) * constant}
|
||||
{@const [width, height, sum] = [box.width * constant, box.height, box.width * constant + box.height]}
|
||||
<div>{area} {volume} {perimeter}, {width}+{height}={sum}</div>
|
||||
{:else}
|
||||
{@const double = constant + constant}
|
||||
<div>{constant} * 2 = {double}</div>
|
||||
{/each}
|
||||
Loading…
Reference in new issue