def test_from_url(self):
     self.assertIsInstance(
         CodeforcesService.from_url('http://codeforces.com/'),
         CodeforcesService)
     self.assertIsInstance(
         CodeforcesService.from_url('https://codeforces.com/'),
         CodeforcesService)
     self.assertIsInstance(
         CodeforcesService.from_url(
             'https://codeforces.com/problemset/problem/700/B'),
         CodeforcesService)
     self.assertIsNone(CodeforcesService.from_url('https://atcoder.jp/'))
Exemplo n.º 2
0
class LoginTest(unittest.TestCase):
    def snippet_call_login_check_failure(self, url):
        with tests.utils.sandbox(files=[]) as tempdir:
            path = 'cookie.jar'  # use dummy cookie to check in an empty state
            proc = tests.utils.run(['--cookie', path, 'login', '--check', url])
            self.assertEqual(proc.returncode, 1)

    def snippet_call_login_check_success(self, url):
        tests.utils.run(['login', '--check', url], check=True)

    def test_call_login_check_atcoder_failure(self):
        self.snippet_call_login_check_failure('https://atcoder.jp/')

    def test_call_login_check_codeforces_failure(self):
        self.snippet_call_login_check_failure('https://codeforces.com/')

    def test_call_login_check_hackerrank_failure(self):
        self.snippet_call_login_check_failure('https://www.hackerrank.com/')

    def test_call_login_check_topcoder_failure(self):
        self.snippet_call_login_check_failure(
            'https://community.topcoder.com/')

    def test_call_login_check_toph_failure(self):
        self.snippet_call_login_check_failure('https://toph.co/')

    def test_call_login_check_yukicoder_failure(self):
        self.snippet_call_login_check_failure('https://yukicoder.me/')

    @unittest.skipIf(not tests.utils.is_logged_in(AtCoderService()),
                     'login is required')
    def test_call_login_check_atcoder_success(self):
        self.snippet_call_login_check_success('https://atcoder.jp/')

    @unittest.skipIf(not tests.utils.is_logged_in(CodeforcesService()),
                     'login is required')
    def test_call_login_check_codeforces_success(self):
        self.snippet_call_login_check_success('https://codeforces.com/')

    @unittest.skipIf(not tests.utils.is_logged_in(HackerRankService()),
                     'login is required')
    def test_call_login_check_hackerrank_success(self):
        self.snippet_call_login_check_success('https://www.hackerrank.com/')

    @unittest.skipIf(not tests.utils.is_logged_in(TopcoderService()),
                     'login is required')
    def test_call_login_check_topcoder_success(self):
        self.snippet_call_login_check_success(
            'https://community.topcoder.com/')

    @unittest.skipIf(not tests.utils.is_logged_in(TophService()),
                     'login is required')
    def test_call_login_check_toph_success(self):
        self.snippet_call_login_check_success('https://toph.co/')

    @unittest.skipIf(not tests.utils.is_logged_in(YukicoderService()),
                     'login is required')
    def test_call_login_check_yukicoder_success(self):
        self.snippet_call_login_check_success('https://yukicoder.me/')
Exemplo n.º 3
0
 def test_from_url(self):
     self.assertIsInstance(CodeforcesService.from_url('http://codeforces.com/'), CodeforcesService)
     self.assertIsInstance(CodeforcesService.from_url('https://codeforces.com/'), CodeforcesService)
     self.assertIsInstance(CodeforcesService.from_url('https://codeforces.com/problemset/problem/700/B'), CodeforcesService)
     self.assertIsInstance(CodeforcesService.from_url('https://codeforces.com/edu/course/2/lesson/2/1/practice/contest/269100/problem/A'), CodeforcesService)
     self.assertIsNone(CodeforcesService.from_url('https://atcoder.jp/'))
Exemplo n.º 4
0
class SubmitCodeforcesTest(unittest.TestCase):
    @unittest.skipIf(not tests.utils.is_logged_in(CodeforcesService()),
                     'login is required')
    def test_call_submit_beta_1_a(self):

        url = 'https://codeforces.com/contest/1/problem/A'
        code = '\n'.join([
            '#!/usr/bin/env python3',
            'h, w, a = map(int, input().split())',
            'print(((h + a - 1) // a) * ((w + a - 1) // a))',
            '# ' + str(
                int(time.time())
            ),  # to bypass the "You have submitted exactly the same code before" error
        ]) + '\n'
        files = [
            {
                'path': 'a.py',
                'data': code
            },
        ]
        with tests.utils.sandbox(files):
            tests.utils.run(['s', '-y', '--no-open', url, 'a.py'], check=True)

    @unittest.skipIf(not tests.utils.is_logged_in(CodeforcesService()),
                     'login is required')
    def test_call_submit_beta_3_b(self):

        url = 'https://codeforces.com/contest/3/problem/B'
        code = r'''#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define ALL(x) begin(x), end(x)
using namespace std;

int main() {
    // input
    int n, v; cin >> n >> v;
    vector<pair<int, int> > one;
    vector<tuple<int, int, int> > two;
    REP (i, n) {
        int t, p; cin >> t >> p;
        if (t == 1) {
            one.emplace_back(p, i);
        } else {
            two.emplace_back(p, i, -1);
        }
    }

    // solve
    int sum_p = 0;
    vector<int> used;
    sort(ALL(one));
    if (v % 2 == 1 and not one.empty()) {
        int p_i, i; tie(p_i, i) = one.back();
        one.pop_back();
        sum_p += p_i;
        used.push_back(i);
        v -= 1;
    }
    while (one.size() >= 2) {
        int p_i, i; tie(p_i, i) = one.back();
        one.pop_back();
        int p_j, j; tie(p_j, j) = one.back();
        one.pop_back();
        two.emplace_back(p_i + p_j, i, j);
    }
    if (one.size() == 1) {
        int p_i, i; tie(p_i, i) = one.back();
        two.emplace_back(p_i, i, -1);
        one.pop_back();
    }
    sort(ALL(two));
    while (v >= 2 and not two.empty()) {
        int p, i, j; tie(p, i, j) = two.back();
        two.pop_back();
        sum_p += p;
        used.push_back(i);
        if (j != -1) used.push_back(j);
        v -= 2;
    }

    // output
    cout << sum_p << endl;
    REP (i, used.size()) {
        cout << used[i] + 1 << (i + 1 < used.size() ? ' ' : '\n');
    }
    return 0;
}
''' + '// ' + str(
            int(time.time())
        ) + '\n'  # to bypass the "You have submitted exactly the same code before" error
        files = [
            {
                'path': 'main.cpp',
                'data': code
            },
        ]
        with tests.utils.sandbox(files):
            tests.utils.run(['s', '-y', '--no-open', url, 'main.cpp'],
                            check=True)