Week 10 Weekly Test Questions

Test Conditions

These questions must be completed under self-administered exam-like conditions. You must time the test yourself and ensure you comply with the conditions below.

You may access this language documentation while attempting this test:

You may also access manual entries (the man command).

Any violation of the test conditions will results in a mark of zero for the entire weekly test component.


Set up for the test by creating a new directory called test10, changing to this directory, and fetching the provided code by running these commands:

mkdir test10
cd test10
1521 fetch test10

Or, if you're not working on CSE, you can download the provided code as a zip file or a tar file.

weekly test question:
Test if An Environment Variable contains A Non-empty String

Write a C program, is_var_set.c, which takes one argument, the name of environment variable

If the environment variable is set to a non-empty string, it should print 1, otherwise it should print 0.

dcc is_var_set.c -o is_var_set
./is_var_set PATH
1
./is_var_set PAT
0
VAR1=hello ./is_var_set VAR1
1
VAR2='' ./is_var_set VAR2
0
./is_var_set VAR3
0

When you think your program is working you can autotest to run some simple automated tests:

1521 autotest is_var_set
When you are finished working on this exercise you must submit your work by running give:
give cs1521 test10_is_var_set is_var_set.c

weekly test question:
Test if A Pathname is a Directory

Write a C program, is_directory.c, which takes one argument a pathname.

If the pathname exists and is a directory, it should print 1, otherwise it should print 0.

dcc is_directory.c -o is_directory
mkdir test_directory
echo >test_file
./is_directory test_directory
1
./is_directory test_file
0
./is_directory non_existant_path
0
./is_directory /home/cs1521/public_html
1
./is_directory /etc/resolv.conf
0

When you think your program is working you can autotest to run some simple automated tests:

1521 autotest is_directory
When you are finished working on this exercise you must submit your work by running give:
give cs1521 test10_is_directory is_directory.c

weekly test question:
Test if Our Diary is Publically Readable

Write a C program, is_diary_public.c, which prints 1 if a file named $HOME/.diary exists and is publically readable (readable to all users).

It should print 0 otherwise.

By $HOME we mean the value of the environment variable HOME.

dcc is_diary_public.c -o is_diary_public
echo >$HOME/.diary
chmod 644 $HOME/.diary
./is_diary_public
1
chmod 600  $HOME/.diary
./is_diary_public
0
rm $HOME/.diary
./is_diary_public
0

When you think your program is working you can autotest to run some simple automated tests:

1521 autotest is_diary_public
When you are finished working on this exercise you must submit your work by running give:
give cs1521 test10_is_diary_public is_diary_public.c

Submission

When you are finished each exercise make sure you submit your work by running give.

You can run give multiple times. Only your last submission will be marked.

Don't submit any exercises you haven't attempted.

If you are working at home, you may find it more convenient to upload your work via give's web interface.

Remember you have until Wednesday 01 January 00:00 to complete this test.

Automarking will be run by the lecturer several days after the submission deadline for the test, using test cases that you haven't seen: different to the test cases autotest runs for you.

(Hint: do your own testing as well as running autotest)

Test Marks

After automarking is run by the lecturer you can view it here the resulting mark will also be available via via give's web interface or by running this command on a CSE machine:

1521 classrun -sturec

The test exercises for each week are worth in total 1 marks.

The best 6 of your 8 test marks for weeks 3-10 will be summed to give you a mark out of 9.