ํ์์ ๋ง์ถ๋ ๋ชฉ์
์ฝ๋ ํ์์ ์์ฌ์ํต์ ์ผํ์ด๋ค. ์ค๋ ์๊ฐ์ด ์ง๋ ์๋ ์ฝ๋์ ํ์ ์ ์ฐพ์๋ณด๊ธฐ ์ด๋ ค์ธ ์ ๋๋ก ๋ณ๊ฒฝ๋์ด๋ ๋งจ ์ฒ์ ์ก์๋์ ๊ตฌํ ์คํ์ผ๊ณผ ๊ฐ๋ ์ฑ ์์ค์ ์ ์ง๋ณด์ ์ฉ์ด์ฑ๊ณผ ํ์ฅ์ฑ์ ๊ณ์ ์ํฅ์ ๋ฏธ์น๋ค.
์ ๋นํ ํ ๊ธธ์ด๋ฅผ ์ ์งํ๋ผ
์์ Box-Plot๋ ํ๋ก์ ํธ ๋ณ ํ์ผ ๊ธธ์ด๋ฅผ ๋ก๊ทธ ๋ถํฌ๋ก ๋ํ๋ธ ์ฌ์ง์ด๋ค. ์ฆ, ์ธ๋ก์ธก์ด ์กฐ๊ธ๋ง ์ฐจ์ด๋๋ ์ค์ ํ์๋ ํฌ๊ฒ ์ฐจ์ด๋๋ค๋ ๋ง์ด๋ค. ์ฌ๊ธฐ์ ์ ์ ์๋์ ์ 500์ค์ ๋์ง ์๊ณ 200์ค์ ๊ฐ์ง๋ ํ์ผ๋ค๋ก๋ ์ถฉ๋ถํ ์ปค๋ค๋ ์์คํ ์ ๊ตฌ์ถํ ์ ์๋ค๋ ๋ง์ด๋ค.
์ ๋ฌธ ๊ธฐ์ฌ์ฒ๋ผ ์์ฑํ๋ผ
์ฐ๋ฆฌ๊ฐ ์ ๋ฌธ ๊ธฐ์ฌ๋ฅผ ์ฝ์ ๋ ์ด๋ป๊ฒ ์ฝ๋์ง ์๊ฐํด๋ณด์. ๋จผ์ ์ ๋ชฉ์ ๋ณด๊ณ ์ฝ์์ง ๋ง์ง ๊ฒฐ์ ํ๊ณ , ๊ฐ์ฅ ์ต์๋น์ ์์ฝ๋ ๋ฌธ๋จ์ ์ฝ๋๋ค. ๊ทธ๋ฆฌ๊ณ ๋ ์ฝ์์ง ๋ง์ง ๊ณ ๋ฏผํ๋ค. ๊ทธ ์๋ ์๋ ์ธ์ธํ ๋ด์ฉ๋ค์ด ์ ๋ฆฌ๋์ด ์๋ ๊ฒ์ด ์ผ๋ฐ์ ์ด๋ค.
๋ง์ฐฌ๊ฐ์ง๋ก ์์คํ์ผ๋ ์ด๋ฌํ ๋ฐฉ์์ผ๋ก ์์ฑํด์ผ ํ๋ค. ์ด๋ฆ๋ง ๋ณด๊ณ ๋ ์ฌ๋ฐ๋ฅธ ๋ชจ๋์ธ์ง ํ๋จํ ์ ์์ ์ ๋๋ก ์ ๊ฒฝ์ฐ์. ์ฒซ๋ถ๋ถ์๋ ๊ณ ์ถ์ ์์ค ๊ฐ๋ ์ ์ค๋ช ํ๊ณ , ํ์๋ก ๊ฐ์๋ก ์ธ๋ถ์ฌํญ์ ๊ธฐ์ ํ์.
๊ฐ๋ ์ ๋น ํ์ผ๋ก ๋ถ๋ฆฌํ๋ผ
์ฝ๋์ ๊ฐ ์ค์ ์์์ด๋ ์ ์ ๋ํ๋ด๊ณ , ์ฌ๋ฌ ์ค์ ๋ฌถ์์ ์๊ฒฐ๋ ์๊ฐ ํ๋๋ฅผ ํํํ๋ค. ์๊ฐ ์ฌ์ด์๋ ๋น ํ์ ๋ฃ์ด ๋ถ๋ฆฌํ์ฌ ๊ฐ๋ ์ฑ์ ํฅ์์ํค์.
// ๋น ํ์ ๋ฃ์ง ์์ ๊ฒฝ์ฐ
package fitnesse.wikitext.widgets;
import java.util.regex.*;
public class BoldWidget extends ParentWidget {
public static final String REGEXP = "'''.+?'''";
private static final Pattern pattern = Pattern.compile("'''(.+?)'''",
Pattern.MULTILINE + Pattern.DOTALL);
public BoldWidget(ParentWidget parent, String text) throws Exception {
super(parent);
Matcher match = pattern.matcher(text); match.find();
addChildWidgets(match.group(1));}
public String render() throws Exception {
StringBuffer html = new StringBuffer("<b>");
html.append(childHtml()).append("</b>");
return html.toString();
}
}
/ ๋น ํ์ ๋ฃ์ ๊ฒฝ์ฐ
package fitnesse.wikitext.widgets;
import java.util.regex.*;
public class BoldWidget extends ParentWidget {
public static final String REGEXP = "'''.+?'''";
private static final Pattern pattern = Pattern.compile("'''(.+?)'''",
Pattern.MULTILINE + Pattern.DOTALL
);
public BoldWidget(ParentWidget parent, String text) throws Exception {
super(parent);
Matcher match = pattern.matcher(text);
match.find();
addChildWidgets(match.group(1));
}
public String render() throws Exception {
StringBuffer html = new StringBuffer("<b>");
html.append(childHtml()).append("</b>");
return html.toString();
}
}
์ธ๋ก ๋ฐ์ง๋
์ค ๋ฐ๊ฟ์ด ๊ฐ๋ ์ ๋ถ๋ฆฌํ๋ค๋ฉด, ์ธ๋ก ๋ฐ์ง๋๋ ์ฐ๊ด์ฑ์ ์๋ฏธํ๋ค. ์ฆ, ์๋ก ๋ฐ์ ํ ์ฝ๋ ํ์ ์ธ๋ก๋ก ๊ฐ๊น์ด ๋์ฌ์ผ ํ๋ค๋ ๋ป์ด๋ค.
// ์๋ฏธ์๋ ์ฃผ์์ผ๋ก ๋ณ์๋ฅผ ๋จ์ด๋จ๋ ค ๋์์ ํ๋์ ํ์
์ด ์ ์๋๋ค.
public class ReporterConfig {
/**
* The class name of the reporter listener
*/
private String m_className;
/**
* The properties of the reporter listener
*/
private List<Property> m_properties = new ArrayList<Property>();
public void addProperty(Property property) {
m_properties.add(property);
}
// ์๋ฏธ ์๋ ์ฃผ์์ ์ ๊ฑฐํจ์ผ๋ก์จ ์ฝ๋๊ฐ ํ๋์ ๋ค์ด์จ๋ค.
// ๋ณ์ 2๊ฐ์ ๋ฉ์๋๊ฐ 1๊ฐ์ธ ํด๋์ค๋ผ๋ ์ฌ์ค์ด ๋๋ฌ๋๋ค.
public class ReporterConfig {
private String m_className;
private List<Property> m_properties = new ArrayList<Property>();
public void addProperty(Property property) {
m_properties.add(property);
}
์์ง ๊ฑฐ๋ฆฌ
ํจ์ ์ฐ๊ด ๊ด๊ณ๋ฅผ ํตํ ๋์ ๋ฐฉ์์ ์ดํดํ๋ ค๊ณ ์ด ํจ์, ์ ํจ์๋ฅผ ์ค๊ฐ๋ฉด์ ์ ์๋๋ก ์ฐพ์ ํด๋ฉจ๋ ๊ฒฝํ์ด ์์ ๊ฒ์ด๋ค. ํน์ ์์๊ด๊ณ๋ฅผ ์ค์คํ ๊ฑฐ์ฌ๋ฌ์ ์ฌ๋ผ๊ฐ ๊ฒฝํ๋ ์์ ๊ฒ์ด๋ค. ๋ณ๋ก ์ข์ ๊ฒฝํ์ผ๋ก ๋จ์ง ์์์ ๊ฒ์ด๋ผ ์๊ฐํ๋ค. ์ด๋ฌํ ๋ฌ๊ฐ์ง ์์ ๊ฒฝํ์ ๋ณธ์ง์๋ ์ด๋์ ์๋์ง ์ฐพ๊ณ ๊ธฐ์ตํ๋๋ฐ ์์ด ๋ ธ๋ ฅ์ ์๋ชจํ๋ค๋ ์ ์ ์๋ค.
์ด๋ฌํ ์ ์์ ์ฐ๋ฆฌ๊ฐ ์์ค์ฝ๋๋ฅผ ์์ฑํ ๋ ๋ฐ์ ํ ๊ฐ๋ ์ ์ธ๋ก์ ๋๋ ๋ ธ๋ ฅ์ด ํ์ํ๋ค. ๋ ๊ฐ๋ ์ด ์๋ก ๋ค๋ฅธ ํ์ผ์ ์ํ๋ค๋ฉด ์ด ๊ท์น์ด ํตํ์ง ์๋๋ค. ํ์ง๋ง ํ๋นํ ๊ทผ๊ฑฐ๊ฐ ์๋ค๋ฉด ํ ํ์ผ์์ ํด๋น ๊ฐ๋ ์ด ์ํ๋ ๊ฒ์ด ๋ง๋ ํ๋ค. ์ด๋ฐ ๊ฒฝ์ฐ, ๊ฐ์ ํ์ผ์์ ์ํ ์ ๋๋ก ๋ฐ์ ํ ๋ ๊ฐ๋ ์ด ์๋ ๊ฒฝ์ฐ, ์ธ๋ก ๊ฑฐ๋ฆฌ๋ก ์ฐ๊ด์ฑ์ ํํํ์. ์ง๋์น๊ฒ ๋ฉ๋ฆฌ ๋จ์ด์ ธ ์์ผ๋ฉด ์ฝ๋ ์ฌ๋์ด ์ฌ๊ธฐ์ ๊ธฐ๋ฅผ ๋ค์ ธ์ผ ํ๋ค.
๋ณ์ ์ ์ธ
๋ณ์๋ ์ฌ์ฉํ๋ ์์น์ ์ต๋ํ ๊ฐ๊น์ด ์ ์ธํ์. ์ฐ๋ฆฌ๊ฐ ์ค๊ณํ ํจ์๋ ๋งค์ฐ ์งง์ผ๋ฏ๋ก (3์ฅ: ํจ์) ์ง์ญ ๋ณ์๋ ๊ฐ ํจ์ ๋งจ ์ฒ์์ ์ ์ธํ์.
// InputStream์ด ํจ์ ๋งจ ์ฒ์์ ์ ์ธ ๋์ด์๋ค. ์๋ ์ฌ์ค ์ข ๊ธธ๋ค
private static void readPreferences() {
InputStream is = null;
try {
is = new FileInputStream(getPreferencesFile());
setPreferences(new Properties(getPreferences()));
getPreferences().load(is);
} catch (IOException e) {
try {
if (is != null)
is.close();
} catch (IOException e1) {
}
}
}
// ๋ชจ๋๋ค ์๋ค์ํผ ๋ฃจํ ์ ์ด ๋ณ์๋ Test each์ฒ๋ผ ๋ฃจํ ๋ฌธ ๋ด๋ถ์ ์ ์ธ
public int countTestCases() {
int count = 0;
for (Test each : tests) // HERE!
count += each.countTestCases();
return count;
}
// ๋๋ฌผ์ง๋ง, ๊ธด ํจ์์์๋ ๋ธ๋ก ์๋จ ๋๋ ๋ฃจํ ์ง์ ์ ๋ณ์๋ฅผ ์ ์ธ ํ ์๋ ์๋ค.
...
for (XmlTest test : m_suite.getTests()) {
TestRunner tr = m_runnerFactory.newTestRunner(this, test); // HERE!!
tr.addListener(m_textReporter);
m_testRunners.add(tr);
invoker = tr.getInvoker();
for (ITestNGMethod m : tr.getBeforeSuiteMethods()) {
beforeSuiteMethods.put(m.getMethod(), m);
}
for (ITestNGMethod m : tr.getAfterSuiteMethods()) {
afterSuiteMethods.put(m.getMethod(), m);
}
}
...
์ธ์คํด์ค ๋ณ์
์ธ์คํด์ค ๋ณ์๋ ํด๋์ค ๋งจ ์ฒ์์ ์ ์ธํ๋ค(์๋ฐ์ ๊ฒฝ์ฐ). ์ ์ค๊ณํ ํด๋์ค๋ ๋๋ค์ ํด๋์ค ๋ฉ์๋๊ฐ ์ธ์คํด์ค ๋ณ์๋ฅผ ์ฌ์ฉํ๊ธฐ ๋๋ฌธ์ด๋ค. c++์ ๊ฒฝ์ฐ ๋ง์ง๋ง์ ์ ์ธํ๋ ๊ฒ์ด ์ผ๋ฐ์ ์ด๋ค. ์ฌ๊ธฐ์ ํต์ฌ์ ์ด๋ ๊ณณ์ด๋ ์ ์๋ ค์ง ์์น์ ์ธ์คํด์ค ๋ณ์๋ฅผ ๋ชจ์ผ๋ ๊ฒ์ด ์ค์ํ๋ค๋ ๊ฒ์ด๋ค.
// ๋์ค์ ์ ์ธ๋ ๋ณ์๋ ๊ฝ๊ฝ ์จ๊ฒจ๋์ ๋ณด๋ฌผ ์ฐพ๊ธฐ์ ๊ฐ๋ค. ์ญ์ค ํ๊ตฌ ์ฝ๋๋ฅผ ์ฝ๋ค๊ฐ ์ฐ์ฐํ ๋ฐ๊ฒฌํ๋ค. ๋ฐ๊ฒฌํด๋ณด์๊ธธ.
// ์์ฆ์ IDE๊ฐ ์ ๋์ด์์ด์ ์ฐพ๊ธฐ์ผ ์ด๋ ต์ง ์๊ฒ ์ง๋ง, ๋๋ฌ์ด๊ฑด ๋ง์ฐฌ๊ฐ์ง
public class TestSuite implements Test {
static public Test createTest(Class<? extends TestCase> theClass,
String name) {
...
}
public static Constructor<? extends TestCase>
getTestConstructor(Class<? extends TestCase> theClass)
throws NoSuchMethodException {
...
}
public static Test warning(final String message) {
...
}
private static String exceptionToString(Throwable t) {
...
}
private String fName;
private Vector<Test> fTests= new Vector<Test>(10);
public TestSuite() { }
public TestSuite(final Class<? extends TestCase> theClass) {
...
}
public TestSuite(Class<? extends TestCase> theClass, String name) {
...
}
... ... ... ... ...
}
์ข ์ ํจ์
ํ ํจ์๊ฐ ๋ค๋ฅธ ํจ์๋ฅผ ํธ์ถํ๋ค๋ฉด ๋ ํจ์๋ ์ธ๋ก๋ก ๊ฐ๊น์ด ๋ฐฐ์นํ๋ค. ๊ฐ๋ฅํ๋ฉด ํธ์ถํ๋ ํจ์๋ฅผ ํธ์ถ๋๋ ํจ์๋ณด๋ค ๋จผ์ ๋ฐฐ์นํ๋ค. ์ฆ, ๋ณดํต์ ์ถ์ํ๋ ๋ฒจ์ด ์์์ ๋์ ๊ฒ์ด๋ฏ๋ก(== ์ ์์ค ์ถ์ํํจ์๋ฅผ ํธ์ถํจ์ผ๋ก) ํ์์ ์ ์์ค ์ถ์ํ ํจ์๋ฅผ ๋์. ์ด๋ ๊ฒ ํ๋ฉด ํ๋ก๊ทธ๋จ์ด ์์ฐ์ค๋ฝ๊ฒ ์ฝํ๋ค. ์ด๋ฐ ๊ท์น์ ์ ์ฉํ๋ค๋ฉด ์ฝ๋ ์ฌ๋๋ ์ด๋ฌํ ๋ถ๋ถ์ โ์์ธกโํ๋ฉด์ ์ฝ๊ฒ ์ฝ์ ์ ์๋ค.
/*์ฒซ์งธ ํจ์์์ ๊ฐ์ฅ ๋จผ์ ํธ์ถํ๋ ํจ์๊ฐ ๋ฐ๋ก ์๋ ์ ์๋๋ค.
๋ค์์ผ๋ก ํธ์ถํ๋ ํจ์๋ ๊ทธ ์๋์ ์ ์๋๋ค. ๊ทธ๋ฌ๋ฏ๋ก ํธ์ถ๋๋ ํจ์๋ฅผ ์ฐพ๊ธฐ๊ฐ ์ฌ์์ง๋ฉฐ
์ ์ฒด ๊ฐ๋
์ฑ๋ ๋์์ง๋ค.*/
/*makeResponse ํจ์์์ ํธ์ถํ๋ getPageNameOrDefaultํจ์ ์์์ "FrontPage" ์์๋ฅผ ์ฌ์ฉํ์ง ์๊ณ ,
์์๋ฅผ ์์์ผ ์๋ฏธ ์ ๋ฌ์ด ์ฌ์์ง๋ ํจ์ ์์น์์ ์ค์ ์ฌ์ฉํ๋ ํจ์๋ก ์์๋ฅผ ๋๊ฒจ์ฃผ๋ ๋ฐฉ๋ฒ์ด
๊ฐ๋
์ฑ ๊ด์ ์์ ํจ์ฌ ๋ ์ข๋ค*/
public class WikiPageResponder implements SecureResponder {
protected WikiPage page;
protected PageData pageData;
protected String pageTitle;
protected Request request;
protected PageCrawler crawler;
// ๊ณ ์์ค
public Response makeResponse(FitNesseContext context, Request request) throws Exception {
String pageName = getPageNameOrDefault(request, "FrontPage");
loadPage(pageName, context);
if (page == null)
return notFoundResponse(context, request);
else
return makePageResponse(context);
}
private String getPageNameOrDefault(Request request, String defaultPageName) {
String pageName = request.getResource();
if (StringUtil.isBlank(pageName))
pageName = defaultPageName;
return pageName;
}
protected void loadPage(String resource, FitNesseContext context)
throws Exception {
WikiPagePath path = PathParser.parse(resource);
crawler = context.root.getPageCrawler();
crawler.setDeadEndStrategy(new VirtualEnabledPageCrawler());
page = crawler.getPage(context.root, path);
if (page != null)
pageData = page.getData();
}
private Response notFoundResponse(FitNesseContext context, Request request)
throws Exception {
return new NotFoundResponder().makeResponse(context, request);
}
private SimpleResponse makePageResponse(FitNesseContext context)
throws Exception {
pageTitle = PathParser.render(crawler.getFullPath(page));
String html = makeHtml(context);
SimpleResponse response = new SimpleResponse();
response.setMaxAge(0);
response.setContent(html);
return response;
}
...
๊ฐ๋ ์ ์ ์ฌ์ฑ
๊ฐ๋ ์ ์ธ ์นํ๋๊ฐ ๋์ ์๋ก ์ฝ๋๋ฅผ ์๋ก ๊ฐ๊น์ด ๋ฐฐ์นํ๋ค. ์์์ ๋งํ ๋ด์ฉ๋ค์ด ํด๋น ๋ฒ์ฃผ์ ์ํ๋๋ฐ, ์ฆ, ํ ํจ์๊ฐ ๋ค๋ฅธ ํจ์๋ฅผ ํธ์ถํ๋ ์ข ์์ฑ, ๋ณ์์ ๊ทธ ๋ณ์๋ฅผ ์ฌ์ฉํ๋ ํจ์๋ฑ์ด ๊ทธ ์์ด๋ค. ํน์ ๋น์ทํ ๋์์ ์ํํ๋ ํจ์ ๋ฌด๋ฆฌ๋ ๊ทธ ์์ ์ํ ์ ์๊ฒ ๋ค.
// ๊ฐ์ assert ๊ด๋ จ๋ ๋์๋ค์ ์ํํ๋ฉฐ, ๋ช
๋ช
๋ฒ์ด ๋๊ฐ๊ณ ๊ธฐ๋ณธ ๊ธฐ๋ฅ์ด ์ ์ฌํ ํจ์๋ค๋ก์จ ๊ฐ๋
์ ์นํ๋๊ฐ ๋๋ค.
// ์ด๋ฐ ๊ฒฝ์ฐ์๋ ์ข
์์ฑ์ ์คํ๋ ค ๋ถ์ฐจ์ ์์ธ์ด๋ฏ๋ก, ์ข
์์ ์ธ ๊ด๊ณ๊ฐ ์๋๋ผ๋ ๊ฐ๊น์ด ๋ฐฐ์นํ๋ฉด ์ข๋ค.
public class Assert {
static public void assertTrue(String message, boolean condition) {
if (!condition)
fail(message);
}
static public void assertTrue(boolean condition) {
assertTrue(null, condition);
}
static public void assertFalse(String message, boolean condition) {
assertTrue(message, !condition);
}
static public void assertFalse(boolean condition) {
assertFalse(null, condition);
}
...
์ธ๋ก ์์
์ผ๋ฐ์ ์ผ๋ก ํจ์ ํธ์ถ ์ข ์์ฑ์ ์๋๋ฐฉํฅ์ผ๋ก ์ ์งํ๋ฏ๋ก, ํธ์ถ๋๋ ํจ์๋ฅผ ํธ์ถํ๋ ํจ์๋ณด๋ค ๋ค์ ๋ฐฐ์นํ๋ค. ์์ฐ์ค๋ฝ๊ฒ ๊ณ ์ฐจ์์์ ์ ์ฐจ์์ผ๋ก ๋ด๋ ค๊ฐ๋ ์ฝ๋๋ฅผ ๋ง๋ค ์ ์๋ค. ์ค์ํ ๊ฐ๋ ์ ๊ฐ์ฅ ์์, ์ธ์ธํ ์ฌํญ์ ๋ง์ง๋ง์.
๊ฐ๋ก ํ์ ๋ง์ถ๊ธฐ
์ ํ๋ ๊ฐ๋ก์ ํ ๊ธธ์ด, ์ธ๋ก์ ๋ก๊ทธ ์ค์ผ์ผ๋ก ํ์๋ ํ ์ ๋ถํฌ์ด๋ค. ์ฆ, ํน์ ํ ๊ธธ์ด์ ํด๋นํ๋ ๋ผ์ธ์ด ๋ชํ๋ก๋ ์ฐจ์งํ๊ณ ์๋์ง ํ์ธํ ์ ์๋ ํ์ด๋ค. ์ ๋ณด๋ฉด, 20์์ 60์ ์ฌ์ด์ธ ํ์ด ์ด ํ ์์ 40%์ ๋ฌํ๋ค. 10์ ๋ฏธ๋ง์ 30% ์ ๋์ด๊ณ , 80% ์ด์ฌ์ผ์ด ๊ฒฝ์ฐ ํ์ ์ ์ ์จ์ ๊ธ๊ฒฉํ๊ฒ ๊ฐ์ํ๋ค. ํ๋ก๊ทธ๋๋จธ๋ ์งง์ ํ์ ์ ํธํ๋ค. ๊ฐ๋กํ์ 120์ ์ ๋๋ฅผ ์ ์งํ์
๊ฐ๋ก ๊ณต๋ฐฑ๊ณผ ๋ฐ์ง๋
private void measureLine(String line) {
lineCount++;
// ํํ ๋ณผ ์ ์๋ ์ฝ๋์ธ๋ฐ, ํ ๋น ์ฐ์ฐ์ ์ข์ฐ๋ก ๊ณต๋ฐฑ์ ์ฃผ์ด ์ผ์ชฝ,์ค๋ฅธ์ชฝ ์์๊ฐ ํ์คํ๊ฒ ๊ตฌ๋ถ๋๋ค.
int lineSize = line.length();
totalChars += lineSize;
// ๋ฐ๋ฉด ํจ์์ด๋ฆ๊ณผ ๊ดํธ ์ฌ์ด์๋ ๊ณต๋ฐฑ์ ์์ฐ์ผ๋ก์จ ํจ์์ ์ธ์์ ๋ฐ์ ํจ์ ๋ณด์ฌ์ค๋ค
// ๊ดํธ ์์ ์ธ์๋ผ๋ฆฌ๋ ์ผํ ๋ค์ ๊ณต๋ฐฑ์ ํตํด ์ธ์๊ฐ ๋ณ๊ฐ๋ผ๋ ์ฌ์ค์ ๋ณด์ฌ์ค๋ค.
lineWidthHistogram.addLine(lineSize, lineCount);
recordWidestLine(lineSize);
}
์์ ์ฝ๋ ์์ ๋ง๊ณ ๋ ์ฐ์ฐ์ ์ฐ์ ์์๋ฅผ ๊ฐ์กฐํ๊ธฐ ์ํด ์ฌ์ฉํ๋ค.
return b*b - 4*a*c;
return (-b + pi) / (2*a)
์ด๋ ๊ฒ ๊ณต๋ฐฑ์ ์ ์ฉํ ๊ฒฝ์ฐ ์์ ์ฝ๊ธฐ๊ฐ ๋งค์ฐ ํธํ๋ค. ํ์ง๋ง ์ฝ๋ formatter์ ๋๋ค์๋ ์ฐ์ฐ์ ์ฐ์ ์์๋ฅผ ๊ณ ๋ คํ์ง ๋ชปํ๊ธฐ ๋๋ฌธ์ ๊ฐ์ ๊ฐ๊ฒฉ์ ์ ์ฉํ๋ค. (Q ๊ดํธ๋ก ๋ฌถ์ด์ฃผ๋ ํ๋จ์ ์ด๋ค์ง? ํ ๋ก )
๊ฐ๋ก ์ ๋ ฌ
public class FitNesseExpediter implements ResponseSender {
private Socket socket;
private InputStream input;
private OutputStream output;
private Reques request;
private Response response;
private FitNesseContex context;
protected long requestParsingTimeLimit;
private long requestProgress;
private long requestParsingDeadline;
private boolean hasError;
...
๋ณด๊ธฐ์๋ ์์ฒญ ์ข์๋ณด์ธ๋ค. ๊ทธ๋ฐ๋ฐ, ์ค์ ๋ก ์ฝ์ด๋ณด๋ฉด ๋ค๋ฅด๋ค. ๋ณ์ ์ ํ์ ์์ฐ์ค๋ ๋ฌด์ํ๊ณ ์ด๋ฆ๋ถํฐ ์ฝ๊ฒ ๋๋ค. ๊ทธ๋ฆฌ๊ณ Code formmater๊ฐ ๋ฌด์ํ๊ณ ์๋๋๋ก ๋๋ ค๋๋๋ค. ์ ์ธ๋ถ๊ฐ ๊ธธ๋ค๋ฉด ์คํ๋ ค ๋ถ๋ฆฌํด์ผ ํ๋ ํ์์ฑ์ด ์์์ ๋งํ๋ค.
๋ค์ฌ์ฐ๊ธฐ
๋ค์ฌ์ฐ๊ธฐ๋ ๋ฒ์๋ก ์ด๋ค์ง ๊ณ์ธต์ ํํํ๊ธฐ ์ํ ๊ฒ์ด๋ค.
๋ค์ฌ์ฐ๊ธฐ ๋ฌด์ํ๊ธฐ
๊ฐ๋จํ if๋ฌธ, while๋ฌธ, ์งง์ ํจ์์์ ๋ค์ฌ์ฐ๊ธฐ๋ฅผ ๋ฌด์ํ๊ณ ํ ์ ํน์ด ์๊ธด๋ค.
// ์ด๋ ๊ฒ ํํ์ ๋ค ๋ฃ์ ์ ์๋ค๊ณ ๋ค ๋๋ ค ๋ฐ๋ ๊ฒ์ด ๋ฉ์๋ ์ฝ๋๊ฐ ์๋๋ ๊ฒ! ์์๋์ผ
public class CommentWidget extends TextWidget {
public static final String REGEXP = "^#[^\r\n]*(?:(?:\r\n)|\n|\r)?";
public CommentWidget(ParentWidget parent, String text){super(parent, text);}
public String render() throws Exception {return ""; }
}
// ํ์ค์ด๋ผ๋ ์ ์ฑ์ค๋ฝ๊ฒ ๋ค์ฌ์ฐ๊ธฐ๋ก ๊ฐ์ธ์ฃผ์. ๊ฐ๋
์ฑ์ ์ํด
public class CommentWidget extends TextWidget {
public static final String REGEXP = "^#[^\r\n]*(?:(?:\r\n)|\n|\r)?";
public CommentWidget(ParentWidget parent, String text){
super(parent, text);
}
public String render() throws Exception {
return "";
}
}
ํ์ค์ ๋ฃ์ ๊ฒ๋ณด๋ค ๊ฐํํ ๊ฒ์ด ํจ์ฌ ์ ์ฝํ๋ค.
๊ฐ์ง ๋ฒ์
๋น while ๋ฌธ์ด๋ for๋ฌธ์ ์ ํ๋ ๊ฒฝ์ฐ ๋น ๋ธ๋ก์ ๋ค์ฌ์ฐ๊ณ ๊ดํธ๋ก ๊ฐ์ธ์.
while (dis.readbuf, 0, readBufferSize) != -1)
;
์ด๋ ๊ฒ ํด์ผ ๋์ ๋๋ค๊ณ ํ๋ค. (?? ์ง๋ฌธ)
ํ ๊ท์น
์ฝ๋ฉ ์คํ์ผ์ ์๋ ผํ์ฌ(๊ดํธ๋ฅผ ์ด๋์ ๋ฃ์์ง, ๋ค์ด๋ฐ์ ์ด๋ป๊ฒ ํ ์ง ๋ฑ) IDE Formatter๋ก ์ง์ ํ์ฌ ๊ตฌํํ๋ ๊ฒ์ด ์ณ์ ๋ฐฉ์์ด๋ค. ์ข์ ์ํํธ์จ์ด ์์คํ ์ ์ฝ๊ธฐ ์ฌ์ด ๋ฌธ์๋ก ์ด๋ค์ง๊ณ , ์ฝ๊ธฐ ์ฌ์ด ๋ฌธ์๋ ์คํ์ผ์ด ์ผ๊ด์ ์ด๊ณ ๋งค๋๋ฌ์์ผ ํ๋ค.
๋ฐฅ ์์ ์จ์ ํ์ ๊ท์น
๋์ผ๋ก ์ ์๊ฐ ์ฌ์ฉํ๋ ๊ท์น์ด ์ ์ฉ๋ ์ฝ๋๋ฅผ ์ฒจ๋ถํ๋ค.
public class CodeAnalyzer implements JavaFileAnalysis {
private int lineCount;
private int maxLineWidth;
private int widestLineNumber;
private LineWidthHistogram lineWidthHistogram;
private int totalChars;
public CodeAnalyzer() {
lineWidthHistogram = new LineWidthHistogram();
}
public static List<File> findJavaFiles(File parentDirectory) {
List<File> files = new ArrayList<File>();
findJavaFiles(parentDirectory, files);
return files;
}
private static void findJavaFiles(File parentDirectory, List<File> files) {
for (File file : parentDirectory.listFiles()) {
if (file.getName().endsWith(".java"))
files.add(file);
else if (file.isDirectory())
findJavaFiles(file, files);
}
}
public void analyzeFile(File javaFile) throws Exception {
BufferedReader br = new BufferedReader(new FileReader(javaFile));
String line;
while ((line = br.readLine()) != null)
measureLine(line);
}
private void measureLine(String line) {
lineCount++;
int lineSize = line.length();
totalChars += lineSize;
lineWidthHistogram.addLine(lineSize, lineCount);
recordWidestLine(lineSize);
}
private void recordWidestLine(int lineSize) {
if (lineSize > maxLineWidth) {
maxLineWidth = lineSize;
widestLineNumber = lineCount;
}
}
public int getLineCount() {
return lineCount;
}
public int getMaxLineWidth() {
return maxLineWidth;
}
public int getWidestLineNumber() {
return widestLineNumber;
}
public LineWidthHistogram getLineWidthHistogram() {
return lineWidthHistogram;
}
public double getMeanLineWidth() {
return (double)totalChars/lineCount;
}
public int getMedianLineWidth() {
Integer[] sortedWidths = getSortedWidths();
int cumulativeLineCount = 0;
for (int width : sortedWidths) {
cumulativeLineCount += lineCountForWidth(width);
if (cumulativeLineCount > lineCount/2)
return width;
}
throw new Error("Cannot get here");
}
private int lineCountForWidth(int width) {
return lineWidthHistogram.getLinesforWidth(width).size();
}
private Integer[] getSortedWidths() {
Set<Integer> widths = lineWidthHistogram.getWidths();
Integer[] sortedWidths = (widths.toArray(new Integer[0]));
Arrays.sort(sortedWidths);
return sortedWidths;
}
}
์์ฝ
- ํ์์ ํ์์ ํ์ํ ๋ฐฉํฅ์ผ๋ก ํ๋ค.
- ๊ฐ๋ ์ ๋ชจ์์ ์ ์ฉํ๋ ๊ฒ์ด ์ข๋ค.
- ๊ณ ์์ค์์ ์ ์์ค์ผ๋ก ์ฝ๋๋ฅผ ์ง๋ผ.
- ํ ์๋ 40-80, ํ ๊ธธ์ด์ 120