ReScript ট্র্যাকে টেস্ট করা

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.

এরর মেসেজটি মন দিয়ে পড়ুন, কারণ এটি সাধারণত সরাসরি সমস্যাটিই চিহ্নিত করে।