Exercism पर अपने ReScript अभ्यासों का टेस्ट करना सीखिए।
जिस अभ्यास पर आप काम करना चाहते हैं, उसे डाउनलोड करने के लिए Exercism CLI का उपयोग कीजिए।
exercism download --track=rescript --exercise=hello-world
इसके बाद अभ्यास की डायरेक्टरी में चले जाइए।
cd /path/to/exercism/rescript/hello-world
टेस्ट चलाने से पहले अभ्यास की डिपेंडेंसी इंस्टॉल कीजिए।
npm install
दिए गए टेस्ट सूट को exercism test या npm run test से कंपाइल करके चलाइए।
टेस्ट रनर हर टेस्ट के रन को पास या फेल की स्थिति के साथ दिखाता है।
1/3: no name given
PASS - no name given
2/3: a name given
FAIL - a name given
---
operator: equal
left: One for you, one for me.
right: One for Alice, one for me.
...
3/3: another name given
FAIL - another name given
---
operator: equal
left: One for you, one for me.
right: One for Bob, one for me.
...
# Ran 3 tests (3 assertions)
# 1 passed
# 2 failed
left वह है जो आपके कोड ने लौटाया। right वह है जिसकी उम्मीद टेस्ट को थी।
two-fer/
├── src/
│ ├── TwoFer.res // your solution goes here
│ └── TwoFer.resi // the optional interface file containing signatures
├── tests/
│ └── TwoFer_test.res // your test suite
├── package.json // used to install project dependencies
└── ...
यहाँ TwoFer.resi एक वैकल्पिक इंटरफेस फाइल है।
जब यह मौजूद होती है, तो यह वे फंक्शन सिग्नेचर बताती है जो आपके हल में होने चाहिए, और यह इस बात का संकेत भी दे सकती है कि क्या बनाना है।
उदाहरण के लिए, अगर इंटरफेस यह घोषित करता है:
let hello: unit => string
तो आपको यह बनाना चाहिए:
let hello = () => "Hello, World!"
अगर आपका कोड कंपाइल नहीं होता, तो ReScript का कंपाइलर सटीक जगह और अपेक्षित टाइप के साथ विस्तृत एरर संदेश देता है।
We've found a bug for you!
1 │ let x: string = 42
This has type: int
But it's expected to have type: string
You can convert int to string with Int.toString.
एरर संदेश को ध्यान से पढ़िए, क्योंकि यह आमतौर पर सीधे समस्या की ओर इशारा करता है।