From 38390ee5d54fcbd32b07362897d132a525a2afbe Mon Sep 17 00:00:00 2001 From: "Sakamoto, Kazunori" Date: Tue, 17 Sep 2024 21:39:40 +0900 Subject: [PATCH] fix: refine problemData --- .../(withAuth)/courses/[courseId]/Course.tsx | 18 +- .../[languageId]/[programId]/BaseProblem.tsx | 30 +- .../[programId]/CheckpointProblem.tsx | 53 +- .../[programId]/ExecutionResultProblem.tsx | 52 +- .../[languageId]/[programId]/StepProblem.tsx | 51 +- .../(withAuth)/courses/[courseId]/page.tsx | 17 +- src/app/(withAuth)/courses/page.tsx | 6 +- .../molecules/TurtleGraphicsController.tsx | 2 +- .../trpcBackend/routers/index.ts | 8 +- src/problems/problemData.ts | 1702 +++++++++-------- 10 files changed, 1023 insertions(+), 916 deletions(-) diff --git a/src/app/(withAuth)/courses/[courseId]/Course.tsx b/src/app/(withAuth)/courses/[courseId]/Course.tsx index 43eb3435..1d5c63cf 100644 --- a/src/app/(withAuth)/courses/[courseId]/Course.tsx +++ b/src/app/(withAuth)/courses/[courseId]/Course.tsx @@ -6,7 +6,6 @@ import NextLink from 'next/link'; import React, { useEffect } from 'react'; import { useLocalStorage } from 'usehooks-ts'; -import { backendTrpcReact } from '../../../../infrastructures/trpcBackend/client'; import { Accordion, AccordionButton, @@ -61,15 +60,10 @@ export const Course: React.FC<{ userCompletedProblems: { programId: string; languageId: VisibleLanguageId }[]; userProblemSessions: UserProblemSessionWithUserAnswers[]; }> = ({ courseId, userCompletedProblems, userProblemSessions }) => { - // TODO: remove the following example code - const getSessionQuery = backendTrpcReact.getSession.useQuery(); - console.log('getSessionQuery:', getSessionQuery.isLoading, getSessionQuery.data, getSessionQuery.error); - const [selectedLanguageId, setSelectedLanguageId] = useLocalStorage( selectedLanguageIdKey, defaultLanguageId ); - useEffect(() => { // 念の為、未知の言語が指定された場合、デフォルト言語に設定し直す。 if (!visibleLanguageIds.includes(selectedLanguageId)) { @@ -99,7 +93,7 @@ export const Course: React.FC<{ return count; }; - const SuspendedSession = (programId: string): UserProblemSessionWithUserAnswers | undefined => { + const getSuspendedSession = (programId: string): UserProblemSessionWithUserAnswers | undefined => { return userProblemSessions.find( (session) => session.courseId === courseId && @@ -110,7 +104,7 @@ export const Course: React.FC<{ ) as UserProblemSessionWithUserAnswers | undefined; }; - const firstSession = (programId: string): UserProblemSessionWithUserAnswers | undefined => { + const getFirstSession = (programId: string): UserProblemSessionWithUserAnswers | undefined => { return userProblemSessions.find( (session) => session.courseId === courseId && session.programId === programId && session.languageId === selectedLanguageId @@ -186,7 +180,7 @@ export const Course: React.FC<{ {programIdToName[programId]} - {SuspendedSession(programId) && 挑戦中} + {getSuspendedSession(programId) && 挑戦中}

@@ -201,10 +195,10 @@ export const Course: React.FC<{ )} - {countFailedAnswers(firstSession(programId))} + {countFailedAnswers(getFirstSession(programId))} - {typeof firstSession(programId)?.timeSpent === 'number' - ? Math.floor(totalAnswerTimeSpent(firstSession(programId)) / 1000) + {typeof getFirstSession(programId)?.timeSpent === 'number' + ? Math.floor(totalAnswerTimeSpent(getFirstSession(programId)) / 1000) : 0} diff --git a/src/app/(withAuth)/courses/[courseId]/[languageId]/[programId]/BaseProblem.tsx b/src/app/(withAuth)/courses/[courseId]/[languageId]/[programId]/BaseProblem.tsx index cae562d2..cfd65760 100644 --- a/src/app/(withAuth)/courses/[courseId]/[languageId]/[programId]/BaseProblem.tsx +++ b/src/app/(withAuth)/courses/[courseId]/[languageId]/[programId]/BaseProblem.tsx @@ -156,10 +156,11 @@ export const BaseProblem: React.FC<{ const explanation = getExplanation(programId, languageId); - const ProblemComponent: React.FC = () => { - switch (problemType) { - case 'executionResult': { - return ( + return ( +

+ + {programIdToName[programId]} + {problemType === 'executionResult' ? ( - ); - } - case 'checkpoint': { - return ( + ) : problemType === 'checkpoint' ? ( - ); - } - case 'step': { - return ( + ) : ( - ); - } - } - }; - - return ( -
- - {programIdToName[programId]} - + )}
); diff --git a/src/app/(withAuth)/courses/[courseId]/[languageId]/[programId]/CheckpointProblem.tsx b/src/app/(withAuth)/courses/[courseId]/[languageId]/[programId]/CheckpointProblem.tsx index 242fc158..3844c078 100644 --- a/src/app/(withAuth)/courses/[courseId]/[languageId]/[programId]/CheckpointProblem.tsx +++ b/src/app/(withAuth)/courses/[courseId]/[languageId]/[programId]/CheckpointProblem.tsx @@ -1,12 +1,16 @@ -'use client'; - -import { useEffect, useRef } from 'react'; +import { useEffect, useRef, useState } from 'react'; import { CustomModal } from '../../../../../../components/molecules/CustomModal'; import { SyntaxHighlighter } from '../../../../../../components/organisms/SyntaxHighlighter'; import type { TurtleGraphicsHandle } from '../../../../../../components/organisms/TurtleGraphics'; import { TurtleGraphics } from '../../../../../../components/organisms/TurtleGraphics'; import { + AlertDialog, + AlertDialogBody, + AlertDialogContent, + AlertDialogFooter, + AlertDialogHeader, + AlertDialogOverlay, Box, Button, Flex, @@ -43,6 +47,8 @@ export const CheckpointProblem: React.FC = ({ setCurrentTraceItemIndex, setProblemType, }) => { + console.log('CheckpointProblem'); + const turtleGraphicsRef = useRef(null); const { isOpen: isExplanationModalOpen, @@ -50,10 +56,15 @@ export const CheckpointProblem: React.FC = ({ onOpen: onExplanationModalOpen, } = useDisclosure(); const { isOpen: isHelpModalOpen, onClose: onHelpModalClose, onOpen: onHelpModalOpen } = useDisclosure(); + const { isOpen: isAlertOpen, onClose: onAlertClose, onOpen: onAlertOpen } = useDisclosure(); + const cancelRef = useRef(null); const beforeCheckpointTraceItem = problem.traceItems[beforeTraceItemIndex]; const currentCheckpointTraceItem = problem.traceItems[currentTraceItemIndex]; + const [alertTitle, setAlertTitle] = useState(''); + const [alertMessage, setAlertMessage] = useState(''); + const handleClickResetButton = (): void => { turtleGraphicsRef.current?.init(); }; @@ -63,17 +74,19 @@ export const CheckpointProblem: React.FC = ({ createAnswerLog(isPassed); - // TODO: 一旦アラートで表示 if (isPassed) { setBeforeTraceItemIndex(currentTraceItemIndex); if (currentCheckpointTraceItem.sid === problem.checkpointSids.at(-1)) { - // 最終チェックポイントを正解した場合はその次の行からステップ問題に移行 - alert('正解です。このチェックポイントから1行ずつ回答してください'); + setAlertTitle('正解'); + setAlertMessage('正解です。このチェックポイントから1行ずつ回答してください'); + onAlertOpen(); setCurrentTraceItemIndex(currentTraceItemIndex + 1); setProblemType('step'); } else { - alert('正解です。次のチェックポイントに進みます'); + setAlertTitle('正解'); + setAlertMessage('正解です。次のチェックポイントに進みます'); + onAlertOpen(); const nextCheckpointTraceItemIndex = problem.traceItems.findIndex( (traceItem) => traceItem.sid === @@ -82,8 +95,9 @@ export const CheckpointProblem: React.FC = ({ setCurrentTraceItemIndex(nextCheckpointTraceItemIndex); } } else { - // 不正解の場合は最後に正解したチェックポイントからステップ問題に移行 - alert('不正解です。最後に正解したチェックポイントから1行ずつ回答してください'); + setAlertTitle('不正解'); + setAlertMessage('不正解です。最後に正解したチェックポイントから1行ずつ回答してください'); + onAlertOpen(); setCurrentTraceItemIndex(beforeTraceItemIndex + 1); setProblemType('step'); } @@ -185,6 +199,27 @@ export const CheckpointProblem: React.FC = ({
+ + + + + {alertTitle} + + {alertMessage} + + + + + + ); }; diff --git a/src/app/(withAuth)/courses/[courseId]/[languageId]/[programId]/ExecutionResultProblem.tsx b/src/app/(withAuth)/courses/[courseId]/[languageId]/[programId]/ExecutionResultProblem.tsx index 65a27bc5..da93b8da 100644 --- a/src/app/(withAuth)/courses/[courseId]/[languageId]/[programId]/ExecutionResultProblem.tsx +++ b/src/app/(withAuth)/courses/[courseId]/[languageId]/[programId]/ExecutionResultProblem.tsx @@ -1,12 +1,16 @@ -'use client'; - -import { useEffect, useRef } from 'react'; +import { useEffect, useRef, useState } from 'react'; import { CustomModal } from '../../../../../../components/molecules/CustomModal'; import { SyntaxHighlighter } from '../../../../../../components/organisms/SyntaxHighlighter'; import type { TurtleGraphicsHandle } from '../../../../../../components/organisms/TurtleGraphics'; import { TurtleGraphics } from '../../../../../../components/organisms/TurtleGraphics'; import { + AlertDialog, + AlertDialogBody, + AlertDialogContent, + AlertDialogFooter, + AlertDialogHeader, + AlertDialogOverlay, Box, Button, Flex, @@ -37,6 +41,8 @@ export const ExecutionResultProblem: React.FC = ({ setCurrentTraceItemIndex, setProblemType, }) => { + console.log('ExecutionResultProblem'); + const turtleGraphicsRef = useRef(null); const { isOpen: isExplanationModalOpen, @@ -44,6 +50,12 @@ export const ExecutionResultProblem: React.FC = ({ onOpen: onExplanationModalOpen, } = useDisclosure(); const { isOpen: isHelpModalOpen, onClose: onHelpModalClose, onOpen: onHelpModalOpen } = useDisclosure(); + const { isOpen: isAlertOpen, onClose: onAlertClose, onOpen: onAlertOpen } = useDisclosure(); + const cancelRef = useRef(null); + console.log('isAlertOpen:', isAlertOpen); + + const [alertTitle, setAlertTitle] = useState(''); + const [alertMessage, setAlertMessage] = useState(''); const handleClickResetButton = (): void => { turtleGraphicsRef.current?.init(); @@ -54,20 +66,25 @@ export const ExecutionResultProblem: React.FC = ({ createAnswerLog(isPassed); - // TODO: 一旦アラートで表示 if (isPassed) { - alert('正解です。この問題は終了です'); + setAlertTitle('正解'); + setAlertMessage('正解です。この問題は終了です'); + onAlertOpen(); handleComplete(); } else { if (problem.checkpointSids.length > 0) { - alert('不正解です。チェックポイントごとに回答してください'); + setAlertTitle('不正解'); + setAlertMessage('不正解です。チェックポイントごとに回答してください'); + onAlertOpen(); const nextCheckpointTraceItemIndex = problem.traceItems.findIndex( (traceItem) => traceItem.sid === problem.checkpointSids.at(0) ); setCurrentTraceItemIndex(nextCheckpointTraceItemIndex); setProblemType('checkpoint'); } else { - alert('不正解です。ステップごとに回答してください'); + setAlertTitle('不正解'); + setAlertMessage('不正解です。ステップごとに回答してください'); + onAlertOpen(); setCurrentTraceItemIndex(1); setProblemType('step'); } @@ -149,6 +166,27 @@ export const ExecutionResultProblem: React.FC = ({ + + + + + {alertTitle} + + {alertMessage} + + + + + + ); }; diff --git a/src/app/(withAuth)/courses/[courseId]/[languageId]/[programId]/StepProblem.tsx b/src/app/(withAuth)/courses/[courseId]/[languageId]/[programId]/StepProblem.tsx index ac71ddbc..3e05251d 100644 --- a/src/app/(withAuth)/courses/[courseId]/[languageId]/[programId]/StepProblem.tsx +++ b/src/app/(withAuth)/courses/[courseId]/[languageId]/[programId]/StepProblem.tsx @@ -1,12 +1,16 @@ -'use client'; - -import { useEffect, useRef } from 'react'; +import { useEffect, useRef, useState } from 'react'; import { CustomModal } from '../../../../../../components/molecules/CustomModal'; import { SyntaxHighlighter } from '../../../../../../components/organisms/SyntaxHighlighter'; import type { TurtleGraphicsHandle } from '../../../../../../components/organisms/TurtleGraphics'; import { TurtleGraphics } from '../../../../../../components/organisms/TurtleGraphics'; import { + AlertDialog, + AlertDialogBody, + AlertDialogContent, + AlertDialogFooter, + AlertDialogHeader, + AlertDialogOverlay, Box, Button, Flex, @@ -42,6 +46,8 @@ export const StepProblem: React.FC = ({ setBeforeTraceItemIndex, setCurrentTraceItemIndex, }) => { + console.log('StepProblem'); + const turtleGraphicsRef = useRef(null); const { isOpen: isExplanationModalOpen, @@ -49,10 +55,15 @@ export const StepProblem: React.FC = ({ onOpen: onExplanationModalOpen, } = useDisclosure(); const { isOpen: isHelpModalOpen, onClose: onHelpModalClose, onOpen: onHelpModalOpen } = useDisclosure(); + const { isOpen: isAlertOpen, onClose: onAlertClose, onOpen: onAlertOpen } = useDisclosure(); + const cancelRef = useRef(null); const beforeCheckpointTraceItem = problem.traceItems[beforeTraceItemIndex]; const currentCheckpointTraceItem = problem.traceItems[currentTraceItemIndex]; + const [alertTitle, setAlertTitle] = useState(''); + const [alertMessage, setAlertMessage] = useState(''); + const handleClickResetButton = (): void => { turtleGraphicsRef.current?.init(); }; @@ -62,18 +73,23 @@ export const StepProblem: React.FC = ({ createAnswerLog(isPassed); - // TODO: 一旦アラートで表示 if (isPassed) { if (currentCheckpointTraceItem === problem.traceItems.at(-1)) { - alert('正解です。この問題は終了です'); + setAlertTitle('正解'); + setAlertMessage('正解です。この問題は終了です'); + onAlertOpen(); handleComplete(); } else { - alert('正解です。次の行に進みます'); + setAlertTitle('正解'); + setAlertMessage('正解です。次の行に進みます'); + onAlertOpen(); setBeforeTraceItemIndex(currentTraceItemIndex); setCurrentTraceItemIndex(currentTraceItemIndex + 1); } } else { - alert('不正解です。もう一度回答してください'); + setAlertTitle('不正解'); + setAlertMessage('不正解です。もう一度回答してください'); + onAlertOpen(); } }; @@ -173,6 +189,27 @@ export const StepProblem: React.FC = ({ + + + + + {alertTitle} + + {alertMessage} + + + + + + ); }; diff --git a/src/app/(withAuth)/courses/[courseId]/page.tsx b/src/app/(withAuth)/courses/[courseId]/page.tsx index 68019842..43883f2f 100644 --- a/src/app/(withAuth)/courses/[courseId]/page.tsx +++ b/src/app/(withAuth)/courses/[courseId]/page.tsx @@ -10,17 +10,14 @@ import { Course } from './Course'; const CoursePage: NextPage<{ params: { courseId: CourseId } }> = async ({ params }) => { const { session } = await getNullableSessionOnServer(); - const user = - session && - (await prisma.user.findUnique({ - where: { - id: session.superTokensUserId, - }, - })); + if (!session) return redirect('/auth'); - if (!user) { - return redirect('/auth'); - } + const user = await prisma.user.findUnique({ + where: { + id: session.superTokensUserId, + }, + }); + if (!user) return redirect('/auth'); const courseId = params.courseId; const userCompletedProblems = await fetchUserCompletedProblems(user.id, courseId); diff --git a/src/app/(withAuth)/courses/page.tsx b/src/app/(withAuth)/courses/page.tsx index 572cc78c..d5150657 100644 --- a/src/app/(withAuth)/courses/page.tsx +++ b/src/app/(withAuth)/courses/page.tsx @@ -1,17 +1,13 @@ import type { NextPage } from 'next'; import NextLink from 'next/link'; -import { Box, Heading, LinkBox, LinkOverlay, List, ListItem, Text } from '../../../infrastructures/useClient/chakra'; +import { Box, Heading, LinkBox, LinkOverlay, List, ListItem } from '../../../infrastructures/useClient/chakra'; import { courseIds, courseIdToName } from '../../../problems/problemData'; -import { getNonNullableSessionOnServer } from '../../../utils/session'; const CoursesPage: NextPage = async () => { - const session = await getNonNullableSessionOnServer(); - return (
- User ID: {session.superTokensUserId} Courses diff --git a/src/components/molecules/TurtleGraphicsController.tsx b/src/components/molecules/TurtleGraphicsController.tsx index 111b9dff..9ae83c86 100644 --- a/src/components/molecules/TurtleGraphicsController.tsx +++ b/src/components/molecules/TurtleGraphicsController.tsx @@ -1,7 +1,7 @@ 'use client'; import React from 'react'; -import { FaArrowRotateRight, FaArrowRotateLeft, FaTrashCan } from 'react-icons/fa6'; +import { FaArrowRotateLeft, FaArrowRotateRight, FaTrashCan } from 'react-icons/fa6'; import { TURTLE_GRAPHICS_GRID_ROWS as GRID_ROWS, TURTLE_GRAPHICS_GRID_SIZE as GRID_SIZE } from '../../constants'; import { Box, Button, HStack, IconButton, VStack } from '../../infrastructures/useClient/chakra'; diff --git a/src/infrastructures/trpcBackend/routers/index.ts b/src/infrastructures/trpcBackend/routers/index.ts index 1315d8e5..ea3b9cbb 100644 --- a/src/infrastructures/trpcBackend/routers/index.ts +++ b/src/infrastructures/trpcBackend/routers/index.ts @@ -68,8 +68,8 @@ export const backendRouter = router({ }, data, }); - revalidatePath('/courses', 'layout'); - console.log('revalidatePath()'); + revalidatePath('/courses/[courseId]/[languageId]', 'page'); + console.log(`revalidatePath('/courses/[courseId]/[languageId]', 'page');`); return userProblemSession; }), createUserCompletedProblem: procedure @@ -91,8 +91,8 @@ export const backendRouter = router({ languageId: input.languageId, }, }); - revalidatePath('/courses', 'layout'); - console.log('revalidatePath()'); + revalidatePath('/courses/[courseId]/[languageId]', 'page'); + console.log(`revalidatePath('/courses/[courseId]/[languageId]', 'page');`); }), createUserAnswer: procedure .use(authorize) diff --git a/src/problems/problemData.ts b/src/problems/problemData.ts index 1940a77d..36b249c1 100644 --- a/src/problems/problemData.ts +++ b/src/problems/problemData.ts @@ -136,1063 +136,1087 @@ export function getExplanation(programId: ProgramId, languageId: VisibleLanguage export const programIdToLanguageIdToProgram: Record> = { straight: { instrumented: ` - s.set('c', new Character()); - s.get('c').forward(); // CP - s.get('c').forward(); - `.trim(), +s.set('c', new Character()); +s.get('c').forward(); // CP +s.get('c').forward(); + `.trim(), java: ` public class Main { - public static void main(String[] args) { - Turtle 亀 = new Turtle(); // sid - 亀.前に進む(); // sid - 亀.前に進む(); // sid - } + public static void main(String[] args) { + Turtle 亀 = new Turtle(); // sid + 亀.前に進む(); // sid + 亀.前に進む(); // sid + } } - `.trim(), + `.trim(), }, stepBack: { instrumented: ` - s.set('c', new Character()); - s.get('c').forward(); // CP - s.get('c').backward(); - `.trim(), +s.set('c', new Character()); +s.get('c').forward(); // CP +s.get('c').backward(); + `.trim(), java: ` public class Main { - public static void main(String[] args) { - Turtle 亀 = new Turtle(); // sid - 亀.前に進む(); // sid - 亀.後に戻る(); // sid - } + public static void main(String[] args) { + Turtle 亀 = new Turtle(); // sid + 亀.前に進む(); // sid + 亀.後に戻る(); // sid + } } - `.trim(), + `.trim(), }, turnRight: { instrumented: ` - s.set('c', new Character()); - s.get('c').forward(); - s.get('c').turnRight(); // CP - s.get('c').forward(); - `.trim(), +s.set('c', new Character()); +s.get('c').forward(); +s.get('c').turnRight(); // CP +s.get('c').forward(); + `.trim(), java: ` public class Main { - public static void main(String[] args) { - Turtle 亀 = new Turtle(); // sid - 亀.前に進む(); // sid - 亀.右を向く(); // sid - 亀.前に進む(); // sid - } -} - `.trim(), + public static void main(String[] args) { + Turtle 亀 = new Turtle(); // sid + 亀.前に進む(); // sid + 亀.右を向く(); // sid + 亀.前に進む(); // sid + } +} + `.trim(), }, turnRightAndTurnLeft: { instrumented: ` - s.set('c', new Character()); - s.get('c').turnRight(); - s.get('c').forward(); - s.get('c').turnLeft(); // CP - s.get('c').forward(); - `.trim(), +s.set('c', new Character()); +s.get('c').turnRight(); +s.get('c').forward(); +s.get('c').turnLeft(); // CP +s.get('c').forward(); + `.trim(), java: ` public class Main { - public static void main(String[] args) { - Turtle 亀 = new Turtle(); // sid - 亀.右を向く(); // sid - 亀.前に進む(); // sid - 亀.左を向く(); // sid - 亀.前に進む(); // sid - } -} - `.trim(), + public static void main(String[] args) { + Turtle 亀 = new Turtle(); // sid + 亀.右を向く(); // sid + 亀.前に進む(); // sid + 亀.左を向く(); // sid + 亀.前に進む(); // sid + } +} + `.trim(), }, square1: { instrumented: ` - s.set('c', new Character()); - s.get('c').forward(); - s.get('c').turnRight(); - s.get('c').forward(); // CP - s.get('c').turnRight(); - s.get('c').forward(); +s.set('c', new Character()); +s.get('c').forward(); +s.get('c').turnRight(); +s.get('c').forward(); // CP +s.get('c').turnRight(); +s.get('c').forward(); `.trim(), java: ` public class Main { - public static void main(String[] args) { - Turtle 亀 = new Turtle(); // sid - 亀.前に進む(); // sid - 亀.右を向く(); // sid - 亀.前に進む(); // sid - 亀.右を向く(); // sid - 亀.前に進む(); // sid - } -} - `.trim(), + public static void main(String[] args) { + Turtle 亀 = new Turtle(); // sid + 亀.前に進む(); // sid + 亀.右を向く(); // sid + 亀.前に進む(); // sid + 亀.右を向く(); // sid + 亀.前に進む(); // sid + } +} + `.trim(), }, square2: { instrumented: ` - s.set('c', new Character(<1-5>, <1-4>)); - s.get('c').forward(); - s.get('c').turnRight(); - s.get('c').forward(); // CP - s.get('c').turnRight(); - s.get('c').forward(); +s.set('c', new Character(<1-5>, <1-4>)); +s.get('c').forward(); +s.get('c').turnRight(); +s.get('c').forward(); // CP +s.get('c').turnRight(); +s.get('c').forward(); `.trim(), java: ` public class Main { - public static void main(String[] args) { - Turtle 亀 = new Turtle(<1-5>, <1-4>); // sid - 亀.前に進む(); // sid - 亀.右を向く(); // sid - 亀.前に進む(); // sid - 亀.右を向く(); // sid - 亀.前に進む(); // sid - } -} - `.trim(), + public static void main(String[] args) { + Turtle 亀 = new Turtle(<1-5>, <1-4>); // sid + 亀.前に進む(); // sid + 亀.右を向く(); // sid + 亀.前に進む(); // sid + 亀.右を向く(); // sid + 亀.前に進む(); // sid + } +} + `.trim(), }, variable: { instrumented: ` - s.set('x', <1-5>); - s.set('c', new Character(s.get('x'), <1-5>)); // CP - s.get('c').forward(); +s.set('x', <1-5>); +s.set('c', new Character(s.get('x'), <1-5>)); // CP +s.get('c').forward(); `.trim(), java: ` public class Main { - public static void main(String[] args) { - int x = <1-5>; // sid - Turtle 亀 = new Turtle(x, <1-5>); // sid - 亀.前に進む(); // sid - } + public static void main(String[] args) { + int x = <1-5>; // sid + Turtle 亀 = new Turtle(x, <1-5>); // sid + 亀.前に進む(); // sid + } } - `.trim(), + `.trim(), }, variable2: { instrumented: ` - s.set('x', <1-5>); - s.set('x', s.get('x') + 1); - s.set('y', s.get('x') + 1); - s.set('c', new Character(s.get('x'), s.get('y'))); // CP - s.get('c').forward(); +s.set('x', <1-5>); +s.set('x', s.get('x') + 1); +s.set('y', s.get('x') + 1); +s.set('c', new Character(s.get('x'), s.get('y'))); // CP +s.get('c').forward(); `.trim(), java: ` public class Main { - public static void main(String[] args) { - int x = <1-5>; // sid - x = x + 1; // sid - int y = x + 1; // sid - Turtle 亀 = new Turtle(x, y); // sid - 亀.前に進む(); // sid - } -} - `.trim(), + public static void main(String[] args) { + int x = <1-5>; // sid + x = x + 1; // sid + int y = x + 1; // sid + Turtle 亀 = new Turtle(x, y); // sid + 亀.前に進む(); // sid + } +} + `.trim(), }, variable3: { instrumented: ` - s.set('x', <1-5>); - s.set('x', s.get('x') - 1); - s.set('y', s.get('x') * 2); - s.set('y', Math.floor(s.get('y') / 3)); - s.set('c', new Character(s.get('x'), s.get('y'))); // CP - s.get('c').forward(); +s.set('x', <1-5>); +s.set('x', s.get('x') - 1); +s.set('y', s.get('x') * 2); +s.set('y', Math.floor(s.get('y') / 3)); +s.set('c', new Character(s.get('x'), s.get('y'))); // CP +s.get('c').forward(); `.trim(), java: ` public class Main { - public static void main(String[] args) { - int x = <1-5>; // sid - x--; // sid - int y = x * 2; // sid - y /= 3; // sid - Turtle 亀 = new Turtle(x, y); // sid - 亀.前に進む(); // sid - } -} - `.trim(), + public static void main(String[] args) { + int x = <1-5>; // sid + x--; // sid + int y = x * 2; // sid + y /= 3; // sid + Turtle 亀 = new Turtle(x, y); // sid + 亀.前に進む(); // sid + } +} + `.trim(), }, while1: { instrumented: ` - s.set('c', new Character()); - s.set('i', 0); - while (s.get('i') < <3-5>) { - s.get('c').forward(); // CP - s.set('i', s.get('i') + 1); - } - `.trim(), +s.set('c', new Character()); +s.set('i', 0); +while (s.get('i') < <3-5>) { + s.get('c').forward(); // CP + s.set('i', s.get('i') + 1); +} + `.trim(), java: ` public class Main { - public static void main(String[] args) { - Turtle 亀 = new Turtle(); // sid - int i = 0; // sid - while (i < <3-5>) { - 亀.前に進む(); // sid - i++; // sid - } - } -} - `.trim(), + public static void main(String[] args) { + Turtle 亀 = new Turtle(); // sid + int i = 0; // sid + while (i < <3-5>) { + 亀.前に進む(); // sid + i++; // sid + } + } +} + `.trim(), }, while2: { instrumented: ` - s.set('c', new Character()); - s.set('i', 0); - while (s.get('i') < <2-3>) { - s.set('i', s.get('i') + 1); - s.get('c').forward(); // CP - s.get('c').turnRight(); - } - `.trim(), +s.set('c', new Character()); +s.set('i', 0); +while (s.get('i') < <2-3>) { + s.set('i', s.get('i') + 1); + s.get('c').forward(); // CP + s.get('c').turnRight(); +} + `.trim(), java: ` public class Main { - public static void main(String[] args) { - Turtle 亀 = new Turtle(); // sid - int i = 0; // sid - while (i < 2) { - i++; // sid - 亀.前に進む(); // sid - 亀.右を向く(); // sid - } - } -} - `.trim(), + public static void main(String[] args) { + Turtle 亀 = new Turtle(); // sid + int i = 0; // sid + while (i < 2) { + i++; // sid + 亀.前に進む(); // sid + 亀.右を向く(); // sid + } + } +} + `.trim(), }, for1: { instrumented: ` - s.set('c', new Character()); - for (s.set('i', 0); s.get('i') < <3-5>; s.set('i', s.get('i') + 1)) { - s.get('c').forward(); // CP - } - `.trim(), +s.set('c', new Character()); +for (s.set('i', 0); s.get('i') < <3-5>; s.set('i', s.get('i') + 1)) { + s.get('c').forward(); // CP +} + `.trim(), java: ` public class Main { - public static void main(String[] args) { - Turtle 亀 = new Turtle(); // sid - for (int i = 0; i < <3-5>; i++) { // sid - 亀.前に進む(); // sid - } - } -} - `.trim(), + public static void main(String[] args) { + Turtle 亀 = new Turtle(); // sid + for (int i = 0; i < <3-5>; i++) { // sid + 亀.前に進む(); // sid + } + } +} + `.trim(), }, for2: { instrumented: ` - s.set('c', new Character()); - s.set('i', 0); - for (s.set('i', s.get('i')) ; s.get('i') < <2-3>; s.set('i', s.get('i'))) { - s.get('c').forward(); // CP - s.get('c').turnRight(); - s.set('i', s.get('i') + 1); - } - `.trim(), +s.set('c', new Character()); +s.set('i', 0); +for (s.set('i', s.get('i')) ; s.get('i') < <2-3>; s.set('i', s.get('i'))) { + s.get('c').forward(); // CP + s.get('c').turnRight(); + s.set('i', s.get('i') + 1); +} + `.trim(), java: ` public class Main { - public static void main(String[] args) { - Turtle 亀 = new Turtle(); // sid - int i = 0; // sid - for (; i < <2-3>;) { // sid - 亀.前に進む(); // sid - 亀.右を向く(); // sid - i++; // sid - } - } -} - `.trim(), + public static void main(String[] args) { + Turtle 亀 = new Turtle(); // sid + int i = 0; // sid + for (; i < <2-3>;) { // sid + 亀.前に進む(); // sid + 亀.右を向く(); // sid + i++; // sid + } + } +} + `.trim(), }, for3: { instrumented: ` - s.set('x', 0); - for (s.set('i', 2); s.get('i') <= <4-5>; s.set('i', s.get('i') + 1)) { - s.set('x', s.get('x') + s.get('i')); - } - s.set('x', Math.floor(s.get('x') / 3)); - s.set('c', new Character(s.get('x'), 0)); // CP - s.get('c').forward(); - `.trim(), +s.set('x', 0); +for (s.set('i', 2); s.get('i') <= <4-5>; s.set('i', s.get('i') + 1)) { + s.set('x', s.get('x') + s.get('i')); +} +s.set('x', Math.floor(s.get('x') / 3)); +s.set('c', new Character(s.get('x'), 0)); // CP +s.get('c').forward(); + `.trim(), java: ` public class Main { - public static void main(String[] args) { - int x = 0; // sid - for (int i = 2; i <= <4-5>; i++) { // sid - x += i; // sid - } - x /= 3; // sid - Turtle 亀 = new Turtle(x, 0); // sid - 亀.前に進む(); // sid - } -} - `.trim(), + public static void main(String[] args) { + int x = 0; // sid + for (int i = 2; i <= <4-5>; i++) { // sid + x += i; // sid + } + x /= 3; // sid + Turtle 亀 = new Turtle(x, 0); // sid + 亀.前に進む(); // sid + } +} + `.trim(), }, doubleLoop1: { instrumented: ` - s.set('c', new Character()); - for (s.set('i', 0); s.get('i') < <2-3>; s.set('i', s.get('i') + 1)) { - for (s.set('j', 0); s.get('j') < <2-3>; s.set('j', s.get('j') + 1)) { - s.get('c').forward(); // CP - } - s.get('c').turnRight(); - } - `.trim(), +s.set('c', new Character()); +for (s.set('i', 0); s.get('i') < <2-3>; s.set('i', s.get('i') + 1)) { + for (s.set('j', 0); s.get('j') < <2-3>; s.set('j', s.get('j') + 1)) { + s.get('c').forward(); // CP + } + s.get('c').turnRight(); +} + `.trim(), java: ` public class Main { - public static void main(String[] args) { - Turtle t = new Turtle(); // sid - for (int i = 0; i < <2-3>; i++) { // sid - for (int j = 0; j < <2-3>; j++) { // sid - t.前に進む(); // sid - } - t.右を向く(); // sid - } - } -} - `.trim(), + public static void main(String[] args) { + Turtle t = new Turtle(); // sid + for (int i = 0; i < <2-3>; i++) { // sid + for (int j = 0; j < <2-3>; j++) { // sid + t.前に進む(); // sid + } + t.右を向く(); // sid + } + } +} + `.trim(), }, doubleLoop2: { instrumented: ` - s.set('c', new Character()); - for (s.set('i', <3-4>); s.get('i') > 0; s.set('i', s.get('i') - 1)) { - for (s.set('j', 0); s.get('j') < s.get('i'); s.set('j', s.get('j') + 1)) { - s.get('c').forward(); // CP - } - s.get('c').turnRight(); - } - `.trim(), +s.set('c', new Character()); +for (s.set('i', <3-4>); s.get('i') > 0; s.set('i', s.get('i') - 1)) { + for (s.set('j', 0); s.get('j') < s.get('i'); s.set('j', s.get('j') + 1)) { + s.get('c').forward(); // CP + } + s.get('c').turnRight(); +} + `.trim(), java: ` public class Main { - public static void main(String[] args) { - Turtle t = new Turtle(); // sid - for (int i = <3-4>; i > 0; i--) { // sid - for (int j = 0; j < i; j++) { // sid - t.前に進む(); // sid - } - t.右を向く(); // sid - } - } -} - `.trim(), + public static void main(String[] args) { + Turtle t = new Turtle(); // sid + for (int i = <3-4>; i > 0; i--) { // sid + for (int j = 0; j < i; j++) { // sid + t.前に進む(); // sid + } + t.右を向く(); // sid + } + } +} + `.trim(), }, if1: { instrumented: ` - s.set('c', new Character()); - for (s.set('i', 0); s.get('i') < <7-9>; s.set('i', s.get('i') + 1)) { - s.get('c').forward(); - if (s.get('i') % 3 === 2) { - s.get('c').turnRight(); // CP - } - } - `.trim(), +s.set('c', new Character()); +for (s.set('i', 0); s.get('i') < <7-9>; s.set('i', s.get('i') + 1)) { + s.get('c').forward(); + if (s.get('i') % 3 === 2) { + s.get('c').turnRight(); // CP + } +} + `.trim(), java: ` public class Main { - public static void main(String[] args) { - Turtle t = new Turtle(); // sid - for (int i = 0; i < <7-9>; i++) { // sid - t.前に進む(); // sid - if (i % 3 == 2) { - t.右を向く(); // sid - } - } - } -} - `.trim(), + public static void main(String[] args) { + Turtle t = new Turtle(); // sid + for (int i = 0; i < <7-9>; i++) { // sid + t.前に進む(); // sid + if (i % 3 == 2) { + t.右を向く(); // sid + } + } + } +} + `.trim(), }, if2: { instrumented: ` - s.set('c', new Character()); - for (s.set('i', 0); s.get('i') < 4; s.set('i', s.get('i') + 1)) { - s.get('c').forward(); - if (s.get('i') % 2 === 0) { - s.get('c').turnRight(); // CP - } else { - s.get('c').turnLeft(); // CP - } - } - `.trim(), +s.set('c', new Character()); +for (s.set('i', 0); s.get('i') < 4; s.set('i', s.get('i') + 1)) { + s.get('c').forward(); + if (s.get('i') % 2 === 0) { + s.get('c').turnRight(); // CP + } else { + s.get('c').turnLeft(); // CP + } +} + `.trim(), java: ` public class Main { - public static void main(String[] args) { - Turtle t = new Turtle(); // sid - for (int i = 0; i < 4; i++) { // sid - t.前に進む(); // sid - if (i % 2 == 0) { - t.右を向く(); // sid - } else { - t.左を向く(); // sid - } - } - } -} - `.trim(), + public static void main(String[] args) { + Turtle t = new Turtle(); // sid + for (int i = 0; i < 4; i++) { // sid + t.前に進む(); // sid + if (i % 2 == 0) { + t.右を向く(); // sid + } else { + t.左を向く(); // sid + } + } + } +} + `.trim(), }, elseIf1: { instrumented: ` - s.set('c', new Character()); - for (s.set('i', 0); s.get('i') < <4-6>; s.set('i', s.get('i') + 1)) { - if (s.get('i') < <2-3>) { - s.get('c').forward(); - } else if (s.get('i') === <2-3>) { - s.get('c').turnLeft(); // CP - } else { - s.get('c').backward(); // CP - } - } - `.trim(), +s.set('c', new Character()); +for (s.set('i', 0); s.get('i') < <4-6>; s.set('i', s.get('i') + 1)) { + if (s.get('i') < <2-3>) { + s.get('c').forward(); + } else if (s.get('i') === <2-3>) { + s.get('c').turnLeft(); // CP + } else { + s.get('c').backward(); // CP + } +} + `.trim(), java: ` public class Main { - public static void main(String[] args) { - Turtle t = new Turtle(); // sid - for (int i = 0; i < <4-6>, i++) { // sid - if (i < <2-3>) t.前に進む(); // sid - else if (i == <2-3>) t.左を向く(); // sid - else t.後に戻る(); // sid - } - } -} - `.trim(), + public static void main(String[] args) { + Turtle t = new Turtle(); // sid + for (int i = 0; i < <4-6>, i++) { // sid + if (i < <2-3>) t.前に進む(); // sid + else if (i == <2-3>) t.左を向く(); // sid + else t.後に戻る(); // sid + } + } +} + `.trim(), }, elseIf2: { instrumented: ` - s.set('c', new Character()); - for (s.set('i', 0); s.get('i') < <5-7>; s.set('i', s.get('i') + 1)) { - if (s.get('i') % 4 === 0) { - s.get('c').forward(); - } else if (s.get('i') % 4 === 1) { - s.get('c').turnRight(); // CP - } else if (s.get('i') % 4 === 2) { - s.get('c').forward(); // CP - } else { - s.get('c').turnLeft(); // CP - } - } - `.trim(), +s.set('c', new Character()); +for (s.set('i', 0); s.get('i') < <5-7>; s.set('i', s.get('i') + 1)) { + if (s.get('i') % 4 === 0) { + s.get('c').forward(); + } else if (s.get('i') % 4 === 1) { + s.get('c').turnRight(); // CP + } else if (s.get('i') % 4 === 2) { + s.get('c').forward(); // CP + } else { + s.get('c').turnLeft(); // CP + } +} + `.trim(), java: ` public class Main { - public static void main(String[] args) { - Turtle t = new Turtle(); // sid - for (int i = 0; i < <5-7>, i++) { // sid - if (i % 4 == 0) t.前に進む(); // sid - else if (i % 4 == 1) t.右を向く(); // sid - else if (i % 4 == 2) t.前に進む(); // sid - else t.左を向く(); // sid - } - } -} - `.trim(), + public static void main(String[] args) { + Turtle t = new Turtle(); // sid + for (int i = 0; i < <5-7>, i++) { // sid + if (i % 4 == 0) t.前に進む(); // sid + else if (i % 4 == 1) t.右を向く(); // sid + else if (i % 4 == 2) t.前に進む(); // sid + else t.左を向く(); // sid + } + } +} + `.trim(), }, switch1: { instrumented: ` - s.set('c', new Character()); - for (s.set('i', 0); s.get('i') < <5-7>; s.set('i', s.get('i') + 1)) { - switch (s.get('i')) { - case 0: case 1: - s.get('c').forward(); break; - case 2: s.get('c').turnLeft(); break; // CP - default: s.get('c').backward(); break; // CP - } - } - `.trim(), +s.set('c', new Character()); +for (s.set('i', 0); s.get('i') < <5-7>; s.set('i', s.get('i') + 1)) { + switch (s.get('i')) { + case 0: case 1: + s.get('c').forward(); break; + case 2: + s.get('c').turnLeft(); break; // CP + default: + s.get('c').backward(); break; // CP + } +} + `.trim(), java: ` public class Main { - public static void main(String[] args) { - Turtle t = new Turtle(); // sid - for (int i = 0; i < <5-7>; i++) { // sid - switch (i) { - case 0: case 1: - t.前に進む(); break; // sid - case 2: t.左を向く(); break; // sid - default: t.後に戻る(); break; // sid - } - } - } -} - `.trim(), + public static void main(String[] args) { + Turtle t = new Turtle(); // sid + for (int i = 0; i < <5-7>; i++) { // sid + switch (i) { + case 0: case 1: + t.前に進む(); break; // sid + case 2: + t.左を向く(); break; // sid + default: + t.後に戻る(); break; // sid + } + } + } +} + `.trim(), }, switch2: { instrumented: ` - s.set('c', new Character()); - for (s.set('i', 0); s.get('i') < <5-7>; s.set('i', s.get('i') + 1)) { - switch (s.get('i') % 4) { - case 1: s.get('c').turnRight(); break; // CP - case 3: s.get('c').turnLeft(); break; // CP - default: s.get('c').forward(); break; // CP - } - } - `.trim(), +s.set('c', new Character()); +for (s.set('i', 0); s.get('i') < <5-7>; s.set('i', s.get('i') + 1)) { + switch (s.get('i') % 4) { + case 1: + s.get('c').turnRight(); break; // CP + case 3: + s.get('c').turnLeft(); break; // CP + default: + s.get('c').forward(); break; // CP + } +} + `.trim(), java: ` public class Main { - public static void main(String[] args) { - Turtle t = new Turtle(); // sid - for (int i = 0; i < <5-7>; i++) { // sid - switch (i % 4) { - case 1: t.右を向く(); break; // sid - case 3: t.左を向く(); break; // sid - default: t.前に進む(); break; // sid - } - } - } -} - `.trim(), + public static void main(String[] args) { + Turtle t = new Turtle(); // sid + for (int i = 0; i < <5-7>; i++) { // sid + switch (i % 4) { + case 1: + t.右を向く(); break; // sid + case 3: + t.左を向く(); break; // sid + default: + t.前に進む(); break; // sid + } + } + } +} + `.trim(), }, break1: { instrumented: ` - s.set('c', new Character()); - while (true) { - if (!s.get('c').canMoveForward()) break; - s.get('c').forward(); // CP - } - `.trim(), +s.set('c', new Character()); +while (true) { + if (!s.get('c').canMoveForward()) break; + s.get('c').forward(); // CP +} + `.trim(), java: ` public class Main { - public static void main(String[] args) { - Turtle t = new Turtle(); // sid - while (true) { - if (!t.前に進めるか()) break; - t.前に進む(); // sid - } - } -} - `.trim(), + public static void main(String[] args) { + Turtle t = new Turtle(); // sid + while (true) { + if (!t.前に進めるか()) break; + t.前に進む(); // sid + } + } +} + `.trim(), }, break2: { instrumented: ` - s.set('c', new Character(<3-4>,<3-4>)); - while (true) { - if (!s.get('c').canMoveForward()) break; - s.get('c').forward(); - s.get('c').turnRight(); // CP - if (!s.get('c').canMoveForward()) break; - s.get('c').forward(); - s.get('c').turnLeft(); // CP - } - `.trim(), +s.set('c', new Character(<3-4>,<3-4>)); +while (true) { + if (!s.get('c').canMoveForward()) break; + s.get('c').forward(); + s.get('c').turnRight(); // CP + + if (!s.get('c').canMoveForward()) break; + s.get('c').forward(); + s.get('c').turnLeft(); // CP +} + `.trim(), java: ` public class Main { - public static void main(String[] args) { - Turtle t = new Turtle(<3-4>, <3-4>); // sid - while (true) { - if (!t.前に進めるか()) break; - t.前に進む(); // sid - t.右を向く(); // sid - if (!t.前に進めるか()) break; - t.前に進む(); // sid - t.左を向く(); // sid - } - } -} - `.trim(), + public static void main(String[] args) { + Turtle t = new Turtle(<3-4>, <3-4>); // sid + while (true) { + if (!t.前に進めるか()) break; + t.前に進む(); // sid + t.右を向く(); // sid + + if (!t.前に進めるか()) break; + t.前に進む(); // sid + t.左を向く(); // sid + } + } +} + `.trim(), }, break3: { instrumented: ` - s.set('c', new Character(<4-6>, <4-6>)); - for (s.set('i', 0); s.get('i') < 4; s.set('i', s.get('i') + 1)) { - while (true) { - s.get('c').forward(); - if (!s.get('c').canMoveForward()) break; - } - s.get('c').turnRight(); // CP - } - `.trim(), +s.set('c', new Character(<4-6>, <4-6>)); +for (s.set('i', 0); s.get('i') < 4; s.set('i', s.get('i') + 1)) { + while (true) { + s.get('c').forward(); + if (!s.get('c').canMoveForward()) break; + } + s.get('c').turnRight(); // CP +} + `.trim(), java: ` public class Main { - public static void main(String[] args) { - Turtle t = new Turtle(<4-6>, <4-6>); // sid - for (int i = 0; i < 4; i++) { // sid - for (;;) { - t.前に進む(); // sid - if (!t.前に進めるか()) break; - } - t.右を向く(); // sid - } - } -} - `.trim(), + public static void main(String[] args) { + Turtle t = new Turtle(<4-6>, <4-6>); // sid + for (int i = 0; i < 4; i++) { // sid + for (;;) { + t.前に進む(); // sid + if (!t.前に進めるか()) break; + } + t.右を向く(); // sid + } + } +} + `.trim(), }, continue1: { instrumented: ` - s.set('c', new Character()); - for (s.set('i', 0); s.get('i') < <3-5>; s.set('i', s.get('i') + 1)) { - if (s.get('i') == 0) { - continue; - } - s.get('c').forward(); // CP - } - `.trim(), +s.set('c', new Character()); + for (s.set('i', 0); s.get('i') < <3-5>; s.set('i', s.get('i') + 1)) { + if (s.get('i') == 0) { + continue; + } + s.get('c').forward(); // CP +} + `.trim(), java: ` public class Main { - public static void main(String[] args) { - Turtle t = new Turtle(); // sid - for (int i = 0; i < <3-5>; i++) { // sid - if (i == 0) { - continue; - } - t.前に進む(); // sid - } - } -} - `.trim(), + public static void main(String[] args) { + Turtle t = new Turtle(); // sid + for (int i = 0; i < <3-5>; i++) { // sid + if (i == 0) { + continue; + } + t.前に進む(); // sid + } + } +} + `.trim(), }, continue2: { instrumented: ` - s.set('c', new Character()); - for (s.set('i', 0); s.get('i') < <5-7>; s.set('i', s.get('i') + 1)) { - if (s.get('i') % <2-3> == 1) { - s.get('c').turnRight(); // CP - continue; - } - s.get('c').forward(); - } - `.trim(), +s.set('c', new Character()); +for (s.set('i', 0); s.get('i') < <5-7>; s.set('i', s.get('i') + 1)) { + if (s.get('i') % <2-3> == 1) { + s.get('c').turnRight(); // CP + continue; + } + s.get('c').forward(); +} + `.trim(), java: ` public class Main { - public static void main(String[] args) { - Turtle t = new Turtle(); // sid - for (int i = 0; i < <5-7>; i++) { // sid - if (i % <2-3> == 1) { - t.右を向く(); // sid - continue; - } - t.前に進む(); // sid - } - } -} - `.trim(), + public static void main(String[] args) { + Turtle t = new Turtle(); // sid + for (int i = 0; i < <5-7>; i++) { // sid + if (i % <2-3> == 1) { + t.右を向く(); // sid + continue; + } + t.前に進む(); // sid + } + } +} + `.trim(), }, continue3: { instrumented: ` - s.set('c', new Character()); - for (s.set('i', 0); s.get('i') < 2; s.set('i', s.get('i') + 1)) { - for (s.set('j', s.get('i') * 4); s.get('j') < 8; s.set('j', s.get('j') + 1)) { - if (s.get('j') % 4 == 1) { - s.get('c').turnRight(); continue;// CP - } else if (s.get('j') % 4 == 3) { - s.get('c').turnLeft(); continue; // CP - } - s.get('c').forward(); - } - s.get('c').turnLeft(); - } - `.trim(), +s.set('c', new Character()); +for (s.set('i', 0); s.get('i') < 2; s.set('i', s.get('i') + 1)) { + for (s.set('j', s.get('i') * 4); s.get('j') < 8; s.set('j', s.get('j') + 1)) { + if (s.get('j') % 4 == 1) { + s.get('c').turnRight(); continue; // CP + } else if (s.get('j') % 4 == 3) { + s.get('c').turnLeft(); continue; // CP + } + s.get('c').forward(); + } + s.get('c').turnLeft(); +} + `.trim(), java: ` public class Main { - public static void main(String[] args) { - Turtle t = new Turtle(); // sid - for (int i = 0; i < 2; i++) { // sid - for (int j = i * 4; j < 8; j++) { // sid - if (j % 4 == 1) { - t.右を向く(); continue; // sid - } else if (j % 4 == 3) { - t.左を向く(); continue; // sid - } - t.前に進む(); // sid - } - t.左を向く(); // sid - } - } -} - `.trim(), + public static void main(String[] args) { + Turtle t = new Turtle(); // sid + for (int i = 0; i < 2; i++) { // sid + for (int j = i * 4; j < 8; j++) { // sid + if (j % 4 == 1) { + t.右を向く(); continue; // sid + } else if (j % 4 == 3) { + t.左を向く(); continue; // sid + } + t.前に進む(); // sid + } + t.左を向く(); // sid + } + } +} + `.trim(), }, method1: { instrumented: ` - s.set('c', new Character()); - twoStepsForward(s.get('c')); - s.get('c').turnRight(); // CP - threeStepsForward(s.get('c')); +s.set('c', new Character()); +forwardTwoSteps(s.get('c')); +s.get('c').turnRight(); // CP +threeStepsForward(s.get('c')); - function twoStepsForward(c) { - c.forward(); - c.forward(); - } +function forwardTwoSteps(c) { + c.forward(); + c.forward(); +} - function threeStepsForward(c) { - c.forward(); - c.forward(); - c.forward(); - } - `.trim(), +function threeStepsForward(c) { + c.forward(); + c.forward(); + c.forward(); +} + `.trim(), java: ` public class Main { - public static void main(String[] args) { - Turtle t = new Turtle(); // sid: 1 - 二歩前に進める(t); - t.右を向く(); // sid: 2 - 三歩前に進める(t); - } - static void 二歩前に進める(Turtle t) { - t.前に進む(); // sid: 3 - t.前に進む(); // sid: 4 - } - static void 三歩前に進める(Turtle t) { - t.前に進む(); // sid: 5 - t.前に進む(); // sid: 6 - t.前に進む(); // sid: 7 - } -} - `.trim(), + public static void main(String[] args) { + Turtle t = new Turtle(); // sid: 1 + 二歩前に進める(t); + t.右を向く(); // sid: 2 + 三歩前に進める(t); + } + static void 二歩前に進める(Turtle t) { + t.前に進む(); // sid: 3 + t.前に進む(); // sid: 4 + } + static void 三歩前に進める(Turtle t) { + t.前に進む(); // sid: 5 + t.前に進む(); // sid: 6 + t.前に進む(); // sid: 7 + } +} + `.trim(), }, method2: { instrumented: ` - s.set('c', new Character()); - forwardGivenSteps(s.get('c'), <3-4>); - s.get('c').turnRight(); // CP - forwardGivenSteps(s.get('c'), 2); +s.set('c', new Character()); +forwardGivenSteps(s.get('c'), <3-4>); +s.get('c').turnRight(); // CP +forwardGivenSteps(s.get('c'), 2); - function forwardGivenSteps(c, n) { - for (s.set('i', 0); s.get('i') < n; s.set('i', s.get('i') + 1)) { - c.forward(); - } - } - `.trim(), +function forwardGivenSteps(c, n) { +for (s.set('i', 0); s.get('i') < n; s.set('i', s.get('i') + 1)) { + c.forward(); + } +} + `.trim(), java: ` public class Main { - public static void main(String[] args) { - Turtle t = new Turtle(); // sid - N歩前に進める(t, <3-4>); - t.右を向く(); // sid - N歩前に進める(t, 2); - } + public static void main(String[] args) { + Turtle t = new Turtle(); // sid + N歩前に進める(t, <3-4>); + t.右を向く(); // sid + N歩前に進める(t, 2); + } - static void N歩前に進める(Turtle t, int n) { - for (int i = 0; i < n; i++) { // sid - t.前に進む(); // sid - } - } + static void N歩前に進める(Turtle t, int n) { + for (int i = 0; i < n; i++) { // sid + t.前に進む(); // sid + } + } } - `.trim(), + `.trim(), }, method3: { instrumented: ` - s.set('c', new Character()); - twoStepsForward(s.get('c')); - s.get('c').turnRight(); // CP - fourStepsForward(s.get('c')); +s.set('c', new Character()); +forwardTwoSteps(s.get('c')); +s.get('c').turnRight(); // CP +forwardFourSteps(s.get('c')); - function twoStepsForward(c) { - c.forward(); - c.forward(); - } +function forwardTwoSteps(c) { + c.forward(); + c.forward(); +} - function fourStepsForward(c) { - twoStepsForward(c); - twoStepsForward(c); - } - `.trim(), +function forwardFourSteps(c) { + forwardTwoSteps(c); + forwardTwoSteps(c); +} + `.trim(), java: ` public class Main { - public static void main(String[] args) { - Turtle t = new Turtle(); // sid - 二歩前に進める(t); - t.右を向く(); // sid - 四歩前に進める(t); - } - static void 二歩前に進める(Turtle t) { - t.前に進む(); // sid - t.前に進む(); // sid - } - static void 四歩前に進める(Turtle t) { - 二歩前に進める(t); - 二歩前に進める(t); - } -} - `.trim(), + public static void main(String[] args) { + Turtle t = new Turtle(); // sid + 二歩前に進める(t); + t.右を向く(); // sid + 四歩前に進める(t); + } + static void 二歩前に進める(Turtle t) { + t.前に進む(); // sid + t.前に進む(); // sid + } + static void 四歩前に進める(Turtle t) { + 二歩前に進める(t); + 二歩前に進める(t); + } +} + `.trim(), }, return1: { instrumented: ` - s.set('c', new Character()); - s.set('x', double(<2-3>)); // CP - forwardGivenSteps(s.get('c'), s.get('x')); - - function forwardGivenSteps(c, n) { - for (s.set('i', 0); s.get('i') < n; s.set('i', s.get('i') + 1)) { - c.forward(); - } - } +s.set('c', new Character()); +s.set('x', double(<2-3>)); // CP +forwardGivenSteps(s.get('c'), s.get('x')); - function double(a) { - return a * 2; - } - `.trim(), +function forwardGivenSteps(c, n) { +for (s.set('i', 0); s.get('i') < n; s.set('i', s.get('i') + 1)) { + c.forward(); + } +} + +function double(a) { + return a * 2; +} + `.trim(), java: ` public class Main { - public static void main(String[] args) { - Turtle t = new Turtle(); // sid - int x = 二倍する(<2-3>) // sid - N歩前に進める(t, x); - } - static void N歩前に進める(Turtle t, int n) { - for (int i = 0; i < n; i++) { // sid - t.前に進む(); // sid - } - } - static int 二倍する(int a) { - return a * 2; - } -} - `.trim(), + public static void main(String[] args) { + Turtle t = new Turtle(); // sid + int x = 二倍する(<2-3>) // sid + N歩前に進める(t, x); + } + static void N歩前に進める(Turtle t, int n) { + for (int i = 0; i < n; i++) { // sid + t.前に進む(); // sid + } + } + static int 二倍する(int a) { + return a * 2; + } +} + `.trim(), }, return2: { instrumented: ` - s.set('c', new Character()); - forwardGivenSteps(s.get('c'), add(1, 1)); - forwardGivenSteps(s.get('c'), add(1, 2)); +s.set('c', new Character()); +forwardGivenSteps(s.get('c'), add(1, 1)); +forwardGivenSteps(s.get('c'), add(1, 2)); - function forwardGivenSteps(c, n) { - for (s.set('i', 0); s.get('i') < n; s.set('i', s.get('i') + 1)) { - c.forward(); - } - } +function forwardGivenSteps(c, n) { + for (s.set('i', 0); s.get('i') < n; s.set('i', s.get('i') + 1)) { + c.forward(); + } +} - function add(a, b) { - return a + b; - } - `.trim(), +function add(a, b) { + return a + b; +} + `.trim(), java: ` public class Main { - public static void main(String[] args) { - Turtle t = new Turtle(); // sid - N歩前に進める(t, 加算する(1, 1)); - N歩前に進める(t, 加算する(1, 2)); - } - static void N歩前に進める(Turtle t, int n) { - for (int i = 0; i < n; i++) { // sid - t.前に進む(); // sid - } - } - static int 加算する(int a, int b) { - return a + b; // sid - } -} - `.trim(), + public static void main(String[] args) { + Turtle t = new Turtle(); // sid + N歩前に進める(t, 加算する(1, 1)); + N歩前に進める(t, 加算する(1, 2)); + } + static void N歩前に進める(Turtle t, int n) { + for (int i = 0; i < n; i++) { // sid + t.前に進む(); // sid + } + } + static int 加算する(int a, int b) { + return a + b; // sid + } +} + `.trim(), }, return3: { instrumented: ` - s.set('c', new Character()); - for (s.set('i', 0); s.get('i') < 3; s.set('i', s.get('i') + 1)) { - for (s.set('j', 0); s.get('j') < 3; s.set('j', s.get('j') + 1)) { - if (isEqual(s.get('i'), s.get('j'))) s.get('c').turnRight(); // CP - else twoStepsForward(s.get('c')); - } - s.get('c').turnLeft(); - } +s.set('c', new Character()); +for (s.set('i', 0); s.get('i') < 3; s.set('i', s.get('i') + 1)) { + for (s.set('j', 0); s.get('j') < 3; s.set('j', s.get('j') + 1)) { + if (isEqual(s.get('i'), s.get('j'))) + s.get('c').turnRight(); // CP + else + forwardTwoSteps(s.get('c')); + } + s.get('c').turnLeft(); +} - function twoStepsForward(c) { - c.forward(); - c.forward(); - } +function forwardTwoSteps(c) { + c.forward(); + c.forward(); +} - function isEqual(a, b) { - return a == b; - } - `.trim(), +function isEqual(a, b) { + return a == b; +} + `.trim(), java: ` public class Main { - public static void main(String[] args) { - Turtle t = new Turtle(); // sid - for (int i = 0; i < 3; i++) { // sid - for (int j = 0; j < 3; j++) { // sid - if (等しいか(i, j)) t.右を向く(); // sid - else t.二歩前に進める(t); - } - t.左を向く(); // sid - } - } - static void 二歩前に進める(Turtle t) { - t.前に進む(); // sid - t.前に進む(); // sid - } - static boolean 等しいか(int a, int b) { - return a == b; - } -} - `.trim(), + public static void main(String[] args) { + Turtle t = new Turtle(); // sid + for (int i = 0; i < 3; i++) { // sid + for (int j = 0; j < 3; j++) { // sid + if (等しいか(i, j)) + t.右を向く(); // sid + else + t.二歩前に進める(t); + } + t.左を向く(); // sid + } + } + static void 二歩前に進める(Turtle t) { + t.前に進む(); // sid + t.前に進む(); // sid + } + static boolean 等しいか(int a, int b) { + return a == b; + } +} + `.trim(), }, array1: { instrumented: ` - s.set('c', new Character()); - s.set('arr', [2, <1-2>, <1-2>]); // CP - for (s.set('i', 0); s.get('i') < s.get('arr').length; s.set('i', s.get('i') + 1)) { - forwardGivenSteps(s.get('c'), s.get('arr')[s.get('i')]); - s.get('c').turnRight(); // CP - } +s.set('c', new Character()); +s.set('arr', [2, <1-2>, <1-2>]); // CP +for (s.set('i', 0); s.get('i') < s.get('arr').length; s.set('i', s.get('i') + 1)) { + forwardGivenSteps(s.get('c'), s.get('arr')[s.get('i')]); + s.get('c').turnRight(); // CP +} - function forwardGivenSteps(c, n) { - for (s.set('j', 0); s.get('j') < n; s.set('j', s.get('j') + 1)) { - c.forward(); - } - } - `.trim(), +function forwardGivenSteps(c, n) { +for (s.set('j', 0); s.get('j') < n; s.set('j', s.get('j') + 1)) { + c.forward(); + } +} + `.trim(), java: ` public class Main { - public static void main(String[] args) { - Turtle t = new Turtle(); // sid - int[] arr = { 2, <1-2>, <1-2> }; // sid - for (int i = 0; i < arr.length; i++) { // sid - N歩前に進める(t, arr[i]); - t.右を向く(); // sid - } - } - static void N歩前に進める(Turtle t, int n) { - for (int j = 0; j < n; j++) { // sid - t.前に進む(); // sid - } - } -} - `.trim(), + public static void main(String[] args) { + Turtle t = new Turtle(); // sid + int[] arr = { 2, <1-2>, <1-2> }; // sid + for (int i = 0; i < arr.length; i++) { // sid + N歩前に進める(t, arr[i]); + t.右を向く(); // sid + } + } + static void N歩前に進める(Turtle t, int n) { + for (int j = 0; j < n; j++) { // sid + t.前に進む(); // sid + } + } +} + `.trim(), }, array2: { instrumented: ` - s.set('c', new Character()); - s.set('arr', [0, 1, 0, 2, 0]); - for (s.set('i', 0); s.get('i') < s.get('arr').length; s.set('i', s.get('i') + 1)) { - switch (s.get('arr')[s.get('i')]) { - case 0: s.get('c').forward(); break; // CP - case 1: s.get('c').turnRight(); break; - case 2: s.get('c').turnLeft(); break; - } - } - `.trim(), +s.set('c', new Character()); +s.set('arr', [0, 1, 0, 2, 0]); +for (s.set('i', 0); s.get('i') < s.get('arr').length; s.set('i', s.get('i') + 1)) { + switch (s.get('arr')[s.get('i')]) { + case 0: + s.get('c').forward(); break; // CP + case 1: + s.get('c').turnRight(); break; + case 2: + s.get('c').turnLeft(); break; + } +} + `.trim(), java: ` public class Main { - public static void main(String[] args) { - Turtle t = new Turtle(); // sid - int [] arr = { 0, 1, 0, 2, 0 }; // sid - for (int i = 0; i < arr.length; i++) { // sid - switch (arr[i]) { - case 0: - t.前に進む(); break; // sid - case 1: - t.右を向く(); break; // sid - case 2: - t.左を向く(); break; // sid - } - } - } -} - `.trim(), + public static void main(String[] args) { + Turtle t = new Turtle(); // sid + int [] arr = { 0, 1, 0, 2, 0 }; // sid + for (int i = 0; i < arr.length; i++) { // sid + switch (arr[i]) { + case 0: + t.前に進む(); break; // sid + case 1: + t.右を向く(); break; // sid + case 2: + t.左を向く(); break; // sid + } + } + } +} + `.trim(), }, array3: { instrumented: ` - s.set('c', new Character()); - s.set('arr', [0, 1, 0, 2, 0]); - for (const cmd of [0, 1, 0, 2, 0]) { - s.set('cmd', cmd); - switch (s.get('cmd')) { - case 0: s.get('c').forward(); break; // CP - case 1: s.get('c').turnRight(); break; - case 2: s.get('c').turnLeft(); break; - } - } - `.trim(), +s.set('c', new Character()); +s.set('arr', [0, 1, 0, 2, 0]); +for (const cmd of [0, 1, 0, 2, 0]) { + s.set('cmd', cmd); + switch (s.get('cmd')) { + case 0: + s.get('c').forward(); break; // CP + case 1: + s.get('c').turnRight(); break; + case 2: + s.get('c').turnLeft(); break; + } +} + `.trim(), java: ` public class Main { - public static void main(String[] args) { - Turtle t = new Turtle(); // sid - int [] arr = { 0, 1, 0, 2, 0 }; // sid - for (int cmd : array) { // sid - switch (cmd) { - case 0: - t.前に進む(); break; // sid - case 1: - t.右を向く(); break; // sid - case 2: - t.左を向く(); break; // sid - } - } - } -} - `.trim(), + public static void main(String[] args) { + Turtle t = new Turtle(); // sid + int [] arr = { 0, 1, 0, 2, 0 }; // sid + for (int cmd : array) { // sid + switch (cmd) { + case 0: + t.前に進む(); break; // sid + case 1: + t.右を向く(); break; // sid + case 2: + t.左を向く(); break; // sid + } + } + } +} + `.trim(), }, string1: { instrumented: ` - s.set('c', new Character()); - s.set('s', 'frflf'); - for (s.set('i', 0); s.get('i') < s.get('s').length; s.set('i', s.get('i') + 1)) { - switch (s.get('s').charAt(s.get('i'))) { - case 'f': - s.get('c').forward(); break; // CP - case 'r': - s.get('c').turnRight(); break; - case 'l': - s.get('c').turnLeft(); break; - } - } - `.trim(), +s.set('c', new Character()); +s.set('s', 'frflf'); +for (s.set('i', 0); s.get('i') < s.get('s').length; s.set('i', s.get('i') + 1)) { + switch (s.get('s').charAt(s.get('i'))) { + case 'f': + s.get('c').forward(); break; // CP + case 'r': + s.get('c').turnRight(); break; + case 'l': + s.get('c').turnLeft(); break; + } +} + `.trim(), java: ` public class Main { - public static void main(String[] args) { - Turtle t = new Turtle(); // sid - String s = "frflf"; // sid - for (int i = 0; i < s.length(); i++) { // sid - switch (s.charAt(i)) { - case 'f': - t.前に進む(); break; // sid - case 'r': - t.右を向く(); break; // sid - case 'l': - t.左を向く(); break; // sid - } - } - } -} - `.trim(), + public static void main(String[] args) { + Turtle t = new Turtle(); // sid + String s = "frflf"; // sid + for (int i = 0; i < s.length(); i++) { // sid + switch (s.charAt(i)) { + case 'f': + t.前に進む(); break; // sid + case 'r': + t.右を向く(); break; // sid + case 'l': + t.左を向く(); break; // sid + } + } + } +} + `.trim(), }, string2: { instrumented: ` - s.set('c', new Character()); - s.set('s', 'frflf'); - for (const ch of 'frflf') { - s.set('ch', ch); - switch (s.get('ch')) { - case 'f': - s.get('c').forward(); break; // CP - case 'r': - s.get('c').turnRight(); break; - case 'l': - s.get('c').turnLeft(); break; - } - } - `.trim(), +s.set('c', new Character()); +s.set('s', 'frflf'); +for (const ch of 'frflf') { + s.set('ch', ch); + switch (s.get('ch')) { + case 'f': + s.get('c').forward(); break; // CP + case 'r': + s.get('c').turnRight(); break; + case 'l': + s.get('c').turnLeft(); break; + } +} + `.trim(), java: ` public class Main { - public static void main(String[] args) { - Turtle t = new Turtle(); // sid - String s = "frflf"; // sid - for (char ch : s.toCharArray()) { // sid - switch (ch) { - case 'f': - t.前に進む(); break; // sid - case 'r': - t.右を向く(); break; // sid - case 'l': - t.左を向く(); break; // sid - } - } - } -} - `.trim(), + public static void main(String[] args) { + Turtle t = new Turtle(); // sid + String s = "frflf"; // sid + for (char ch : s.toCharArray()) { // sid + switch (ch) { + case 'f': + t.前に進む(); break; // sid + case 'r': + t.右を向く(); break; // sid + case 'l': + t.左を向く(); break; // sid + } + } + } +} + `.trim(), }, string3: { instrumented: ` - s.set('c', new Character()); - s.set('cmds', ['ri', 'aa', 'fo']); // CP - for (const cmd of ['ri', 'aa', 'fo']) { - s.set('cmd', cmd); - parse(s.get('c'), s.get('cmd')); - } +s.set('c', new Character()); +s.set('cmds', ['ri', 'aa', 'fo']); // CP +for (const cmd of ['ri', 'aa', 'fo']) { + s.set('cmd', cmd); + parse(s.get('c'), s.get('cmd')); +} - function parse(t, c) { - if (c === 'fo') t.forward(); - else if (c === 'ri') t.turnRight(); - } - `.trim(), +function parse(t, c) { + if (c === 'fo') t.forward(); + else if (c === 'ri') t.turnRight(); +} + `.trim(), java: ` public class Main { - public static void main(String[] args) { - Turtle t = new Turtle(); // sid - String[] cmds = { "ri", "aa", "fo" }; // sid - for (String cmd : cmds) { // sid - parse(t, cmd); - } - } - static void parse(Turtle t, String c) { - if (c.equals("fo")) t.前に進む(); // sid - else if (c.equals("ri")) t.右を向く(); // sid - } -} - `.trim(), + public static void main(String[] args) { + Turtle t = new Turtle(); // sid + String[] cmds = { "ri", "aa", "fo" }; // sid + for (String cmd : cmds) { // sid + parse(t, cmd); + } + } + static void parse(Turtle t, String c) { + if (c.equals("fo")) + t.前に進む(); // sid + else if (c.equals("ri")) + t.右を向く(); // sid + } +} + `.trim(), }, test1: { instrumented: ` @@ -1251,7 +1275,7 @@ s.set('c', s.get('a') * 2); function f(x, y) { try { s.enterNewScope(); - s.set('ret', x * y); +s.set('ret', x * y); return s.get('ret'); } finally { s.leaveScope();