Skip to content

OctaveCodeQuestion type #631

Description

@davis68

I have created a working OctaveCodeQuestion type using Oct2Py. You can see it at https://github.com/davis68/relate for now. I haven't created a PR yet for it.

  • It uses data_files to include M-files for supporting functions.

  • It has its own new image for Octave. (This is currently messy since I kept a quick update to the image around for development purposes, but once you're satisfied with the extension I will flatten those files into one.)

The following works correctly:

type: OctaveCodeQuestion
id: test_apply_function
value: 1
timeout: 10
title: "Checkpoint:  Applying a Function"
access_rules:
    add_permissions:
        - see_correctness
        - change_answer

prompt: |
    ### Applying a Function

    Apply the provided function `f` to the provided array `x`.  Store the result in `y`.

    (`x` has the value `[ 1 2 3 4 5 ]` but is already defined and available for you.)

setup_code: |
    x = [ 1 2 3 4 5 ];

initial_code: |
    y = f( ___ );

names_for_user: [ x ]

names_from_user: [ y ]

data_files: [ "./question-data/f.m" ]

test_code: |
    pts = 0.0

    try:
        import oct2py
        from oct2py import Struct,Cell,StructArray

        import numpy as np

        oc = oct2py.Oct2Py()
        test_y = oc.eval( "[ 1 2 3 4 5 ].^2;" )
        print(test_y,y )

        assert np.allclose( y,test_y )
        pts = 1.0

    except NameError:
        feedback.finish( 0.0,'Something is wrong.  Have you created `y`?' )
    except AssertionError:
        feedback.finish( 0.0,'Something is wrong.  Have you used `f` on `x` to obtain `y`?' )

    if np.isclose( pts,1.0 ):
        feedback.finish( pts,'Success!' )
    else:
        feedback.finish( pts,'Keep trying.  If you get stuck, please ask a TA for help on Piazza or office hours.' )


correct_code: |
    y = f(x);

What additional documentation and tests would you like to see as part of the PR?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions