<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Qjia2</id>
	<title>Expertiza_Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Qjia2"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Qjia2"/>
	<updated>2026-06-08T20:59:13Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84828</id>
		<title>CSC/ECE 517 Spring 2014/final doc updated qyx</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84828"/>
		<updated>2014-04-29T17:25:20Z</updated>

		<summary type="html">&lt;p&gt;Qjia2: /* course_team.rb */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
== Introduction ==&lt;br /&gt;
This project will be an extension of our [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Spring_2014/oss_E1406_st previous E1406 project]. For the previous project, we did some refactoring and testing for the controllers related to teams. This time, we are going to reuse most of our test environment, but extend the tests to other team-related classes. We also expect to examine and report the code that may require refactoring.&lt;br /&gt;
&lt;br /&gt;
== Test Environment ==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
&lt;br /&gt;
=== Statistics ===&lt;br /&gt;
''Please note that the coverage generate by SimpleCov may be lower than expect due to the added fixtures.''&lt;br /&gt;
&lt;br /&gt;
; Overall (set of 6 tests) : 105 tests, 156 assertions, 2 failures, 3060 / 13457 LOC (22.74%) covered.&lt;br /&gt;
; Unit tests : 18 tests, 18 assertions, 0 failures&lt;br /&gt;
; Functional tests : 87 tests, 138 assertions, 2 failures (reasons of failures can be found in &amp;quot;Possible Bugs&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
== Running Tests ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
Run &lt;br /&gt;
 rake test:prepare&lt;br /&gt;
before each action.&lt;br /&gt;
To run unit tests&lt;br /&gt;
 bundle exec ruby -I.:test -e &amp;quot;ARGV.each{|f| require f}&amp;quot; test/unit/team_test.rb test/unit/course_team_test.rb test/unit/assignment_team_test.rb test/unit/team_user_test.rb&lt;br /&gt;
To run functional tests&lt;br /&gt;
 bundle exec ruby -I.:test -e &amp;quot;ARGV.each{|f| require f}&amp;quot; test/functional/advertise_for_partner_controller_test.rb test/functional/teams_users_controller_test.rb&lt;br /&gt;
You can also run multiple tests&lt;br /&gt;
  bundle exec ruby -I.:test -e &amp;quot;ARGV.each{|f| require f}&amp;quot; test/functional/teams_users_controller_test.rb test/functional/advertise_for_partner_controller_test.rb test/unit/course_team_test.rb test/unit/assignment_team_test.rb test/unit/team_test.rb test/unit/team_user_test.rb&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb===&lt;br /&gt;
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.&lt;br /&gt;
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.&lt;br /&gt;
=== advertise_for_partner.rb ===&lt;br /&gt;
* This controller takes over the advertisement function from the student_team_controller, and make the class more RESTful. &lt;br /&gt;
* It seems like there has been a functional test, but the class name and set up looks like the other class. It may be necessary to re-run, and even re-write the test&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* This model defines the relationship between team object and other objects. It also has other methods to handle related functions about team operation&lt;br /&gt;
* There exists a unit test for team model, but there are only two test cases. Also, some of the methods under team.rb are duplicated, or either marked as not working. Further research may be required before starting to do the test.&lt;br /&gt;
=== assignment_team.rb &amp;amp; course_team.rb ===&lt;br /&gt;
* Both assignment_team class and course_team class are inherited from team class.&lt;br /&gt;
* These two classes have similar methods, which could be used to manage teams for assignment and course more effectively.&lt;br /&gt;
== Summary of Found Issues ==&lt;br /&gt;
=== Changes made to the class===&lt;br /&gt;
==== team.rb ==== &lt;br /&gt;
''Based on the discussion from the demo, the duplicated method was deleted instead of commented out''&lt;br /&gt;
* duplicated def get_participants was removed&lt;br /&gt;
** This is removed because the same method is defined again at line 20&lt;br /&gt;
* duplicated def self.generate_team_name() was removed&lt;br /&gt;
** This is removed because the same method is defined again at line 131&lt;br /&gt;
==== advertise_for_team_controller.rb ====&lt;br /&gt;
* def new was removed&lt;br /&gt;
** since it's empty, there is no need to keep the code there&lt;br /&gt;
&lt;br /&gt;
=== Possible Refactoring ===&lt;br /&gt;
==== team.rb ==== &lt;br /&gt;
* line 81 def self.create_node_object(name, parent_id)&lt;br /&gt;
** see the TODO at line 80, the method will not work.&lt;br /&gt;
=== advertise_for_team_controller.rb ===&lt;br /&gt;
* ''update'' should be ''edit'' (this is mentioned in the comments of code)&lt;br /&gt;
* ''edit'' should be reexamined since it is only assigning the team object&lt;br /&gt;
=== assignment_team.rb ===&lt;br /&gt;
* in &amp;quot;delete&amp;quot; method, before sign_up.each.destory, we need to make sure sign_up is not nil.&lt;br /&gt;
* in &amp;quot;email&amp;quot; method, a method named get_team_users is called but this method has no definition. We should define get_team_users somewhere or delete &amp;quot;email&amp;quot; method.&lt;br /&gt;
=== course_team.rb ===&lt;br /&gt;
* add_participant(course_id, user)method should belong to course rather than course_team. Delete this method.&lt;br /&gt;
* self.export_all_assignment_team_related_to_course(csv, parent_id, options)method should be deleted.&lt;br /&gt;
&lt;br /&gt;
=== teams_user.rb ===&lt;br /&gt;
* ''delete'' method should not call ''team.delete'', comment out corresponding statements.&lt;br /&gt;
* ''self.is_team_empty'' method should not call ''length'', replace corresponding statements with ''count'' method&lt;br /&gt;
&lt;br /&gt;
=== teams_users_controller.rb ===&lt;br /&gt;
* ''delete_selected'' method mistake using ''find'' and ''first'', this method could not work. No test will be made on the method&lt;br /&gt;
&lt;br /&gt;
=== Possible Bugs ===&lt;br /&gt;
==== team.rb ====&lt;br /&gt;
* def add_member(user, assignment_id) allow nil to be passed&lt;br /&gt;
** rails always raise runtime error when nil is passed. [[#unit/team_test.rb|Test: &amp;quot;add member for course should create teams user&amp;quot; ]]&lt;br /&gt;
* def randomize_all_by_parent passing wrong arguments&lt;br /&gt;
** The code is passing wrong arguments in line 124 for add_member, there should be 2 arguments. [[#unit/team_test.rb|Test: &amp;quot;randomize_all_by_parent&amp;quot; ]]&lt;br /&gt;
* def import_team_members passing wrong arguments&lt;br /&gt;
** it is calling add_member and passing nil for assignment_id, which will make rails raise error.[[#unit/team_test.rb|Test: &amp;quot;import team members successfully&amp;quot; ]]&lt;br /&gt;
==== assignment_team.rb ====&lt;br /&gt;
* def self.get_export_fields(options)&lt;br /&gt;
** when the option team_name =&amp;gt; false, the second element of the output array should be &amp;quot;Team members&amp;quot;. But from the test, it is &amp;quot;Assignment Name&amp;quot;. This is one failure from assignment_team_test.rb&lt;br /&gt;
* def add_participant(assignment_id, user)&lt;br /&gt;
** the AssignmentParticipant.count does not increase. This is another failure from assignment_team_test.rb.&lt;br /&gt;
==== teams_user.rb ====&lt;br /&gt;
* def delete(option)&lt;br /&gt;
** should not call ''team.delete'', it will cause recursion error&lt;br /&gt;
* def self.is_team_empty(team_id)&lt;br /&gt;
** rewrite this method without using ''length'' method, the ''length'' method will generate errors here&lt;br /&gt;
==== teams_users_controller.rb ====&lt;br /&gt;
* def delete_selected(options)&lt;br /&gt;
** the statement ''TeamsUser.find(item_id).first'' cannot work, since the method ''find'' will return an exact object, which cannot be applied ''first'' method&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
To set up our testing for the models and controllers, we need some fixtures to support. &lt;br /&gt;
Fixtures needed for corresponding classes are listed below&lt;br /&gt;
'''However, all of the fixtures are required to be in the fixutre folder, otherwise it will raise error.'''&lt;br /&gt;
&lt;br /&gt;
=== fixtures use in common ===&lt;br /&gt;
* teams.yml&lt;br /&gt;
* users.yml &lt;br /&gt;
* teams_users.yml&lt;br /&gt;
* courses.yml&lt;br /&gt;
* assignments.yml&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
* join_team_requests.yml&lt;br /&gt;
* participants.yml&lt;br /&gt;
* nodes.yml&lt;br /&gt;
* questions.yml&lt;br /&gt;
* signed_up_users.yml&lt;br /&gt;
&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_partner_controller.rb ===&lt;br /&gt;
[[File:Usecase_E1414_advertise.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Concerns for Test Cases ==&lt;br /&gt;
&lt;br /&gt;
=== functional/teams_users_controller_test.rb ===&lt;br /&gt;
[[File:TeamUsersStory.png]]&lt;br /&gt;
&lt;br /&gt;
=== functional/teams_users_controller_test.rb ===&lt;br /&gt;
Because most of the tests are straightforward, only tests with concerns are listed.&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Please notice that this method will receive an ''item_id'' and delete the first team user belonging to that item&lt;br /&gt;
&lt;br /&gt;
=== unit/teams_users_test.rb ===&lt;br /&gt;
Only tests with concerns are listed.&lt;br /&gt;
* Delete&lt;br /&gt;
** Notice here we would not test if the method will delete team, only test if it could delete the team user&lt;br /&gt;
&lt;br /&gt;
=== functional/advertise_for_partner_controller_test.rb ===&lt;br /&gt;
*  # test &amp;quot;test update advertisement fail&amp;quot; do&lt;br /&gt;
** should show flash for fail message when team.save fail, but there is no really a good way to fail team.save, so this is not implemented&lt;br /&gt;
&lt;br /&gt;
=== unit/team_test.rb ===&lt;br /&gt;
Most of test should be straightforward, so only the test with concerns will be listed below&lt;br /&gt;
*  test &amp;quot;get_participants from assignment team&amp;quot; do&lt;br /&gt;
** Please notice that this will actually call the get_participants under AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
*  test &amp;quot;generate_team_name&amp;quot; do&lt;br /&gt;
** Please notice that this method (self.generate_team_name)is modified&lt;br /&gt;
&lt;br /&gt;
*  test &amp;quot;add member for course should create teams user&amp;quot; do&lt;br /&gt;
** In the original code, it allow nil to be passed as parameter, and checks for assignment_id = nil, but rails will actually raise runtime error when nil is passed.&lt;br /&gt;
&lt;br /&gt;
*  #test &amp;quot;randomize_all_by_parent&amp;quot; do&lt;br /&gt;
** Commented out because the bug in the code make it raise error because assignment id not passed. (wrong argument)&lt;br /&gt;
&lt;br /&gt;
*  #test &amp;quot;import team members successfully&amp;quot; do&lt;br /&gt;
** problem: add_member are not passing correct assignment id in team.rb&lt;br /&gt;
&lt;br /&gt;
=== unit/assignment_team_test.rb ===&lt;br /&gt;
Because most of the tests are straightforward, only tests with concerns are listed.&lt;br /&gt;
* delete&lt;br /&gt;
** this method has bug. In the method, before sign_up.each.destory, we need to make sure sign_up is not nil. No test&lt;br /&gt;
* email&lt;br /&gt;
** this method has bug because there is no method named get_team_users. No test&lt;br /&gt;
&lt;br /&gt;
=== unit/course_team_test.rb ===&lt;br /&gt;
Only tests with concerns are listed.&lt;br /&gt;
*add_participant(course_id, user)&lt;br /&gt;
** this method should belong to course rather than course_team. This test may be not useful.&lt;br /&gt;
* self.export_all_assignment_team_related_to_course(csv, parent_id, options)&lt;br /&gt;
** this method should be deleted from course_team class. No test&lt;br /&gt;
&lt;br /&gt;
== Possible Refactoring ==&lt;br /&gt;
=== teams_participant.rb &amp;amp; teams_participants_controller.rb ===&lt;br /&gt;
* These two files are never used, no tests will cover them.&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers from our previous work to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
The first piece of code is from student_team_controller.rb. It tests if there is already a same team name when student8 want to create a team. The second piece of code is from teams_controller_test.rb. It tests if the team number decreases when instructor1 creates a new team for a course.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, several parameters are needed. Usually we use four parameters: First, the method we are requesting. Second, an hash of request parameters for the method. Third, an optional hash of session variables. Forth, an optional hash of flash values. If we do not want to pass in the optional hash, we can set it to nil as the first piece of code shows, or we can just leave it blank as the second piece of code shows.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Qjia2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84827</id>
		<title>CSC/ECE 517 Spring 2014/final doc updated qyx</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84827"/>
		<updated>2014-04-29T17:20:04Z</updated>

		<summary type="html">&lt;p&gt;Qjia2: /* Concerns for Test Cases */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
== Introduction ==&lt;br /&gt;
This project will be an extension of our [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Spring_2014/oss_E1406_st previous E1406 project]. For the previous project, we did some refactoring and testing for the controllers related to teams. This time, we are going to reuse most of our test environment, but extend the tests to other team-related classes. We also expect to examine and report the code that may require refactoring.&lt;br /&gt;
&lt;br /&gt;
== Test Environment ==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
&lt;br /&gt;
=== Statistics ===&lt;br /&gt;
''Please note that the coverage generate by SimpleCov may be lower than expect due to the added fixtures.''&lt;br /&gt;
&lt;br /&gt;
; Overall (set of 6 tests) : 105 tests, 156 assertions, 2 failures, 3060 / 13457 LOC (22.74%) covered.&lt;br /&gt;
; Unit tests : 18 tests, 18 assertions, 0 failures&lt;br /&gt;
; Functional tests : 87 tests, 138 assertions, 2 failures (reasons of failures can be found in &amp;quot;Possible Bugs&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
== Running Tests ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
Run &lt;br /&gt;
 rake test:prepare&lt;br /&gt;
before each action.&lt;br /&gt;
To run unit tests&lt;br /&gt;
 bundle exec ruby -I.:test -e &amp;quot;ARGV.each{|f| require f}&amp;quot; test/unit/team_test.rb test/unit/course_team_test.rb test/unit/assignment_team_test.rb test/unit/team_user_test.rb&lt;br /&gt;
To run functional tests&lt;br /&gt;
 bundle exec ruby -I.:test -e &amp;quot;ARGV.each{|f| require f}&amp;quot; test/functional/advertise_for_partner_controller_test.rb test/functional/teams_users_controller_test.rb&lt;br /&gt;
You can also run multiple tests&lt;br /&gt;
  bundle exec ruby -I.:test -e &amp;quot;ARGV.each{|f| require f}&amp;quot; test/functional/teams_users_controller_test.rb test/functional/advertise_for_partner_controller_test.rb test/unit/course_team_test.rb test/unit/assignment_team_test.rb test/unit/team_test.rb test/unit/team_user_test.rb&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb===&lt;br /&gt;
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.&lt;br /&gt;
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.&lt;br /&gt;
=== advertise_for_partner.rb ===&lt;br /&gt;
* This controller takes over the advertisement function from the student_team_controller, and make the class more RESTful. &lt;br /&gt;
* It seems like there has been a functional test, but the class name and set up looks like the other class. It may be necessary to re-run, and even re-write the test&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* This model defines the relationship between team object and other objects. It also has other methods to handle related functions about team operation&lt;br /&gt;
* There exists a unit test for team model, but there are only two test cases. Also, some of the methods under team.rb are duplicated, or either marked as not working. Further research may be required before starting to do the test.&lt;br /&gt;
=== assignment_team.rb &amp;amp; course_team.rb ===&lt;br /&gt;
* Both assignment_team class and course_team class are inherited from team class.&lt;br /&gt;
* These two classes have similar methods, which could be used to manage teams for assignment and course more effectively.&lt;br /&gt;
== Summary of Found Issues ==&lt;br /&gt;
=== Changes made to the class===&lt;br /&gt;
==== team.rb ==== &lt;br /&gt;
''Based on the discussion from the demo, the duplicated method was deleted instead of commented out''&lt;br /&gt;
* duplicated def get_participants was removed&lt;br /&gt;
** This is removed because the same method is defined again at line 20&lt;br /&gt;
* duplicated def self.generate_team_name() was removed&lt;br /&gt;
** This is removed because the same method is defined again at line 131&lt;br /&gt;
==== advertise_for_team_controller.rb ====&lt;br /&gt;
* def new was removed&lt;br /&gt;
** since it's empty, there is no need to keep the code there&lt;br /&gt;
&lt;br /&gt;
=== Possible Refactoring ===&lt;br /&gt;
==== team.rb ==== &lt;br /&gt;
* line 81 def self.create_node_object(name, parent_id)&lt;br /&gt;
** see the TODO at line 80, the method will not work.&lt;br /&gt;
=== advertise_for_team_controller.rb ===&lt;br /&gt;
* ''update'' should be ''edit'' (this is mentioned in the comments of code)&lt;br /&gt;
* ''edit'' should be reexamined since it is only assigning the team object&lt;br /&gt;
=== assignment_team.rb ===&lt;br /&gt;
* in &amp;quot;delete&amp;quot; method, before sign_up.each.destory, we need to make sure sign_up is not nil.&lt;br /&gt;
* in &amp;quot;email&amp;quot; method, a method named get_team_users is called but this method has no definition. We should define get_team_users somewhere or delete &amp;quot;email&amp;quot; method.&lt;br /&gt;
=== course_team.rb ===&lt;br /&gt;
* add_participant(course_id, user)method should belong to course rather than course_team. Delete this method.&lt;br /&gt;
* self.export_all_assignment_team_related_to_course(csv, parent_id, options)method should be deleted.&lt;br /&gt;
&lt;br /&gt;
=== Possible Bugs ===&lt;br /&gt;
==== team.rb ====&lt;br /&gt;
* def add_member(user, assignment_id) allow nil to be passed&lt;br /&gt;
** rails always raise runtime error when nil is passed. [[#unit/team_test.rb|Test: &amp;quot;add member for course should create teams user&amp;quot; ]]&lt;br /&gt;
* def randomize_all_by_parent passing wrong arguments&lt;br /&gt;
** The code is passing wrong arguments in line 124 for add_member, there should be 2 arguments. [[#unit/team_test.rb|Test: &amp;quot;randomize_all_by_parent&amp;quot; ]]&lt;br /&gt;
* def import_team_members passing wrong arguments&lt;br /&gt;
** it is calling add_member and passing nil for assignment_id, which will make rails raise error.[[#unit/team_test.rb|Test: &amp;quot;import team members successfully&amp;quot; ]]&lt;br /&gt;
==== assignment_team.rb ====&lt;br /&gt;
* def self.get_export_fields(options)&lt;br /&gt;
** when the option team_name =&amp;gt; false, the second element of the output array should be &amp;quot;Team members&amp;quot;. But from the test, it is &amp;quot;Assignment Name&amp;quot;. This is one failure from assignment_team_test.rb&lt;br /&gt;
* def add_participant(assignment_id, user)&lt;br /&gt;
** the AssignmentParticipant.count does not increase. This is another failure from assignment_team_test.rb.&lt;br /&gt;
==== teams_user.rb ====&lt;br /&gt;
* def delete(option)&lt;br /&gt;
** should not call ''team.delete'', it will cause recursion error&lt;br /&gt;
* def self.is_team_empty(team_id)&lt;br /&gt;
** rewrite this method without using ''length'' method, the ''length'' method will generate errors here&lt;br /&gt;
==== teams_users_controller.rb ====&lt;br /&gt;
* def delete_selected(options)&lt;br /&gt;
** the statement ''TeamsUser.find(item_id).first'' cannot work, since the method ''find'' will return an exact object, which cannot be applied ''first'' method&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
To set up our testing for the models and controllers, we need some fixtures to support. &lt;br /&gt;
Fixtures needed for corresponding classes are listed below&lt;br /&gt;
'''However, all of the fixtures are required to be in the fixutre folder, otherwise it will raise error.'''&lt;br /&gt;
&lt;br /&gt;
=== fixtures use in common ===&lt;br /&gt;
* teams.yml&lt;br /&gt;
* users.yml &lt;br /&gt;
* teams_users.yml&lt;br /&gt;
* courses.yml&lt;br /&gt;
* assignments.yml&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
* join_team_requests.yml&lt;br /&gt;
* participants.yml&lt;br /&gt;
* nodes.yml&lt;br /&gt;
* questions.yml&lt;br /&gt;
* signed_up_users.yml&lt;br /&gt;
&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_partner_controller.rb ===&lt;br /&gt;
[[File:Usecase_E1414_advertise.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Concerns for Test Cases ==&lt;br /&gt;
&lt;br /&gt;
=== functional/teams_users_controller_test.rb ===&lt;br /&gt;
[[File:TeamUsersStory.png]]&lt;br /&gt;
&lt;br /&gt;
=== functional/teams_users_controller_test.rb ===&lt;br /&gt;
Because most of the tests are straightforward, only tests with concerns are listed.&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Please notice that this method will receive an ''item_id'' and delete the first team user belonging to that item&lt;br /&gt;
&lt;br /&gt;
=== unit/teams_users_test.rb ===&lt;br /&gt;
Only tests with concerns are listed.&lt;br /&gt;
* Delete&lt;br /&gt;
** Notice here we would not test if the method will delete team, only test if it could delete the team user&lt;br /&gt;
&lt;br /&gt;
=== functional/advertise_for_partner_controller_test.rb ===&lt;br /&gt;
*  # test &amp;quot;test update advertisement fail&amp;quot; do&lt;br /&gt;
** should show flash for fail message when team.save fail, but there is no really a good way to fail team.save, so this is not implemented&lt;br /&gt;
&lt;br /&gt;
=== unit/team_test.rb ===&lt;br /&gt;
Most of test should be straightforward, so only the test with concerns will be listed below&lt;br /&gt;
*  test &amp;quot;get_participants from assignment team&amp;quot; do&lt;br /&gt;
** Please notice that this will actually call the get_participants under AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
*  test &amp;quot;generate_team_name&amp;quot; do&lt;br /&gt;
** Please notice that this method (self.generate_team_name)is modified&lt;br /&gt;
&lt;br /&gt;
*  test &amp;quot;add member for course should create teams user&amp;quot; do&lt;br /&gt;
** In the original code, it allow nil to be passed as parameter, and checks for assignment_id = nil, but rails will actually raise runtime error when nil is passed.&lt;br /&gt;
&lt;br /&gt;
*  #test &amp;quot;randomize_all_by_parent&amp;quot; do&lt;br /&gt;
** Commented out because the bug in the code make it raise error because assignment id not passed. (wrong argument)&lt;br /&gt;
&lt;br /&gt;
*  #test &amp;quot;import team members successfully&amp;quot; do&lt;br /&gt;
** problem: add_member are not passing correct assignment id in team.rb&lt;br /&gt;
&lt;br /&gt;
=== unit/assignment_team_test.rb ===&lt;br /&gt;
Because most of the tests are straightforward, only tests with concerns are listed.&lt;br /&gt;
* delete&lt;br /&gt;
** this method has bug. In the method, before sign_up.each.destory, we need to make sure sign_up is not nil. No test&lt;br /&gt;
* email&lt;br /&gt;
** this method has bug because there is no method named get_team_users. No test&lt;br /&gt;
&lt;br /&gt;
=== unit/course_team_test.rb ===&lt;br /&gt;
Only tests with concerns are listed.&lt;br /&gt;
*add_participant(course_id, user)&lt;br /&gt;
** this method should belong to course rather than course_team. This test may be not useful.&lt;br /&gt;
* self.export_all_assignment_team_related_to_course(csv, parent_id, options)&lt;br /&gt;
** this method should be deleted from course_team class. No test&lt;br /&gt;
&lt;br /&gt;
== Possible Refactoring ==&lt;br /&gt;
=== teams_participant.rb &amp;amp; teams_participants_controller.rb ===&lt;br /&gt;
* These two files are never used, no tests will cover them.&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers from our previous work to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
The first piece of code is from student_team_controller.rb. It tests if there is already a same team name when student8 want to create a team. The second piece of code is from teams_controller_test.rb. It tests if the team number decreases when instructor1 creates a new team for a course.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, several parameters are needed. Usually we use four parameters: First, the method we are requesting. Second, an hash of request parameters for the method. Third, an optional hash of session variables. Forth, an optional hash of flash values. If we do not want to pass in the optional hash, we can set it to nil as the first piece of code shows, or we can just leave it blank as the second piece of code shows.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Qjia2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84826</id>
		<title>CSC/ECE 517 Spring 2014/final doc updated qyx</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84826"/>
		<updated>2014-04-29T17:19:27Z</updated>

		<summary type="html">&lt;p&gt;Qjia2: /* Concerns for Test Cases */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
== Introduction ==&lt;br /&gt;
This project will be an extension of our [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Spring_2014/oss_E1406_st previous E1406 project]. For the previous project, we did some refactoring and testing for the controllers related to teams. This time, we are going to reuse most of our test environment, but extend the tests to other team-related classes. We also expect to examine and report the code that may require refactoring.&lt;br /&gt;
&lt;br /&gt;
== Test Environment ==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
&lt;br /&gt;
=== Statistics ===&lt;br /&gt;
''Please note that the coverage generate by SimpleCov may be lower than expect due to the added fixtures.''&lt;br /&gt;
&lt;br /&gt;
; Overall (set of 6 tests) : 105 tests, 156 assertions, 2 failures, 3060 / 13457 LOC (22.74%) covered.&lt;br /&gt;
; Unit tests : 18 tests, 18 assertions, 0 failures&lt;br /&gt;
; Functional tests : 87 tests, 138 assertions, 2 failures (reasons of failures can be found in &amp;quot;Possible Bugs&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
== Running Tests ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
Run &lt;br /&gt;
 rake test:prepare&lt;br /&gt;
before each action.&lt;br /&gt;
To run unit tests&lt;br /&gt;
 bundle exec ruby -I.:test -e &amp;quot;ARGV.each{|f| require f}&amp;quot; test/unit/team_test.rb test/unit/course_team_test.rb test/unit/assignment_team_test.rb test/unit/team_user_test.rb&lt;br /&gt;
To run functional tests&lt;br /&gt;
 bundle exec ruby -I.:test -e &amp;quot;ARGV.each{|f| require f}&amp;quot; test/functional/advertise_for_partner_controller_test.rb test/functional/teams_users_controller_test.rb&lt;br /&gt;
You can also run multiple tests&lt;br /&gt;
  bundle exec ruby -I.:test -e &amp;quot;ARGV.each{|f| require f}&amp;quot; test/functional/teams_users_controller_test.rb test/functional/advertise_for_partner_controller_test.rb test/unit/course_team_test.rb test/unit/assignment_team_test.rb test/unit/team_test.rb test/unit/team_user_test.rb&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb===&lt;br /&gt;
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.&lt;br /&gt;
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.&lt;br /&gt;
=== advertise_for_partner.rb ===&lt;br /&gt;
* This controller takes over the advertisement function from the student_team_controller, and make the class more RESTful. &lt;br /&gt;
* It seems like there has been a functional test, but the class name and set up looks like the other class. It may be necessary to re-run, and even re-write the test&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* This model defines the relationship between team object and other objects. It also has other methods to handle related functions about team operation&lt;br /&gt;
* There exists a unit test for team model, but there are only two test cases. Also, some of the methods under team.rb are duplicated, or either marked as not working. Further research may be required before starting to do the test.&lt;br /&gt;
=== assignment_team.rb &amp;amp; course_team.rb ===&lt;br /&gt;
* Both assignment_team class and course_team class are inherited from team class.&lt;br /&gt;
* These two classes have similar methods, which could be used to manage teams for assignment and course more effectively.&lt;br /&gt;
== Summary of Found Issues ==&lt;br /&gt;
=== Changes made to the class===&lt;br /&gt;
==== team.rb ==== &lt;br /&gt;
''Based on the discussion from the demo, the duplicated method was deleted instead of commented out''&lt;br /&gt;
* duplicated def get_participants was removed&lt;br /&gt;
** This is removed because the same method is defined again at line 20&lt;br /&gt;
* duplicated def self.generate_team_name() was removed&lt;br /&gt;
** This is removed because the same method is defined again at line 131&lt;br /&gt;
==== advertise_for_team_controller.rb ====&lt;br /&gt;
* def new was removed&lt;br /&gt;
** since it's empty, there is no need to keep the code there&lt;br /&gt;
&lt;br /&gt;
=== Possible Refactoring ===&lt;br /&gt;
==== team.rb ==== &lt;br /&gt;
* line 81 def self.create_node_object(name, parent_id)&lt;br /&gt;
** see the TODO at line 80, the method will not work.&lt;br /&gt;
=== advertise_for_team_controller.rb ===&lt;br /&gt;
* ''update'' should be ''edit'' (this is mentioned in the comments of code)&lt;br /&gt;
* ''edit'' should be reexamined since it is only assigning the team object&lt;br /&gt;
=== assignment_team.rb ===&lt;br /&gt;
* in &amp;quot;delete&amp;quot; method, before sign_up.each.destory, we need to make sure sign_up is not nil.&lt;br /&gt;
* in &amp;quot;email&amp;quot; method, a method named get_team_users is called but this method has no definition. We should define get_team_users somewhere or delete &amp;quot;email&amp;quot; method.&lt;br /&gt;
=== course_team.rb ===&lt;br /&gt;
* add_participant(course_id, user)method should belong to course rather than course_team. Delete this method.&lt;br /&gt;
* self.export_all_assignment_team_related_to_course(csv, parent_id, options)method should be deleted.&lt;br /&gt;
&lt;br /&gt;
=== Possible Bugs ===&lt;br /&gt;
==== team.rb ====&lt;br /&gt;
* def add_member(user, assignment_id) allow nil to be passed&lt;br /&gt;
** rails always raise runtime error when nil is passed. [[#unit/team_test.rb|Test: &amp;quot;add member for course should create teams user&amp;quot; ]]&lt;br /&gt;
* def randomize_all_by_parent passing wrong arguments&lt;br /&gt;
** The code is passing wrong arguments in line 124 for add_member, there should be 2 arguments. [[#unit/team_test.rb|Test: &amp;quot;randomize_all_by_parent&amp;quot; ]]&lt;br /&gt;
* def import_team_members passing wrong arguments&lt;br /&gt;
** it is calling add_member and passing nil for assignment_id, which will make rails raise error.[[#unit/team_test.rb|Test: &amp;quot;import team members successfully&amp;quot; ]]&lt;br /&gt;
==== assignment_team.rb ====&lt;br /&gt;
* def self.get_export_fields(options)&lt;br /&gt;
** when the option team_name =&amp;gt; false, the second element of the output array should be &amp;quot;Team members&amp;quot;. But from the test, it is &amp;quot;Assignment Name&amp;quot;. This is one failure from assignment_team_test.rb&lt;br /&gt;
* def add_participant(assignment_id, user)&lt;br /&gt;
** the AssignmentParticipant.count does not increase. This is another failure from assignment_team_test.rb.&lt;br /&gt;
==== teams_user.rb ====&lt;br /&gt;
* def delete(option)&lt;br /&gt;
** should not call ''team.delete'', it will cause recursion error&lt;br /&gt;
* def self.is_team_empty(team_id)&lt;br /&gt;
** rewrite this method without using ''length'' method, the ''length'' method will generate errors here&lt;br /&gt;
==== teams_users_controller.rb ====&lt;br /&gt;
* def delete_selected(options)&lt;br /&gt;
** the statement ''TeamsUser.find(item_id).first'' cannot work, since the method ''find'' will return an exact object, which cannot be applied ''first'' method&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
To set up our testing for the models and controllers, we need some fixtures to support. &lt;br /&gt;
Fixtures needed for corresponding classes are listed below&lt;br /&gt;
'''However, all of the fixtures are required to be in the fixutre folder, otherwise it will raise error.'''&lt;br /&gt;
&lt;br /&gt;
=== fixtures use in common ===&lt;br /&gt;
* teams.yml&lt;br /&gt;
* users.yml &lt;br /&gt;
* teams_users.yml&lt;br /&gt;
* courses.yml&lt;br /&gt;
* assignments.yml&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
* join_team_requests.yml&lt;br /&gt;
* participants.yml&lt;br /&gt;
* nodes.yml&lt;br /&gt;
* questions.yml&lt;br /&gt;
* signed_up_users.yml&lt;br /&gt;
&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_partner_controller.rb ===&lt;br /&gt;
[[File:Usecase_E1414_advertise.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Concerns for Test Cases ==&lt;br /&gt;
&lt;br /&gt;
=== functional/teams_users_controller_test.rb ===&lt;br /&gt;
[[File:TeamUsersStory.png]]&lt;br /&gt;
&lt;br /&gt;
Because most of the tests are straightforward, only tests with concerns are listed.&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Please notice that this method will receive an ''item_id'' and delete the first team user belonging to that item&lt;br /&gt;
&lt;br /&gt;
=== unit/teams_users_test.rb ===&lt;br /&gt;
Only tests with concerns are listed.&lt;br /&gt;
* Delete&lt;br /&gt;
** Notice here we would not test if the method will delete team, only test if it could delete the team user&lt;br /&gt;
&lt;br /&gt;
=== functional/advertise_for_partner_controller_test.rb ===&lt;br /&gt;
*  # test &amp;quot;test update advertisement fail&amp;quot; do&lt;br /&gt;
** should show flash for fail message when team.save fail, but there is no really a good way to fail team.save, so this is not implemented&lt;br /&gt;
&lt;br /&gt;
=== unit/team_test.rb ===&lt;br /&gt;
Most of test should be straightforward, so only the test with concerns will be listed below&lt;br /&gt;
*  test &amp;quot;get_participants from assignment team&amp;quot; do&lt;br /&gt;
** Please notice that this will actually call the get_participants under AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
*  test &amp;quot;generate_team_name&amp;quot; do&lt;br /&gt;
** Please notice that this method (self.generate_team_name)is modified&lt;br /&gt;
&lt;br /&gt;
*  test &amp;quot;add member for course should create teams user&amp;quot; do&lt;br /&gt;
** In the original code, it allow nil to be passed as parameter, and checks for assignment_id = nil, but rails will actually raise runtime error when nil is passed.&lt;br /&gt;
&lt;br /&gt;
*  #test &amp;quot;randomize_all_by_parent&amp;quot; do&lt;br /&gt;
** Commented out because the bug in the code make it raise error because assignment id not passed. (wrong argument)&lt;br /&gt;
&lt;br /&gt;
*  #test &amp;quot;import team members successfully&amp;quot; do&lt;br /&gt;
** problem: add_member are not passing correct assignment id in team.rb&lt;br /&gt;
&lt;br /&gt;
=== unit/assignment_team_test.rb ===&lt;br /&gt;
Because most of the tests are straightforward, only tests with concerns are listed.&lt;br /&gt;
* delete&lt;br /&gt;
** this method has bug. In the method, before sign_up.each.destory, we need to make sure sign_up is not nil. No test&lt;br /&gt;
* email&lt;br /&gt;
** this method has bug because there is no method named get_team_users. No test&lt;br /&gt;
&lt;br /&gt;
=== unit/course_team_test.rb ===&lt;br /&gt;
Only tests with concerns are listed.&lt;br /&gt;
*add_participant(course_id, user)&lt;br /&gt;
** this method should belong to course rather than course_team. This test may be not useful.&lt;br /&gt;
* self.export_all_assignment_team_related_to_course(csv, parent_id, options)&lt;br /&gt;
** this method should be deleted from course_team class. No test&lt;br /&gt;
&lt;br /&gt;
== Possible Refactoring ==&lt;br /&gt;
=== teams_participant.rb &amp;amp; teams_participants_controller.rb ===&lt;br /&gt;
* These two files are never used, no tests will cover them.&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers from our previous work to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
The first piece of code is from student_team_controller.rb. It tests if there is already a same team name when student8 want to create a team. The second piece of code is from teams_controller_test.rb. It tests if the team number decreases when instructor1 creates a new team for a course.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, several parameters are needed. Usually we use four parameters: First, the method we are requesting. Second, an hash of request parameters for the method. Third, an optional hash of session variables. Forth, an optional hash of flash values. If we do not want to pass in the optional hash, we can set it to nil as the first piece of code shows, or we can just leave it blank as the second piece of code shows.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Qjia2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84825</id>
		<title>CSC/ECE 517 Spring 2014/final doc updated qyx</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84825"/>
		<updated>2014-04-29T17:10:08Z</updated>

		<summary type="html">&lt;p&gt;Qjia2: /* Possible Refactoring */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
== Introduction ==&lt;br /&gt;
This project will be an extension of our [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Spring_2014/oss_E1406_st previous E1406 project]. For the previous project, we did some refactoring and testing for the controllers related to teams. This time, we are going to reuse most of our test environment, but extend the tests to other team-related classes. We also expect to examine and report the code that may require refactoring.&lt;br /&gt;
&lt;br /&gt;
== Test Environment ==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
&lt;br /&gt;
=== Statistics ===&lt;br /&gt;
''Please note that the coverage generate by SimpleCov may be lower than expect due to the added fixtures.''&lt;br /&gt;
&lt;br /&gt;
; Overall (set of 6 tests) : 105 tests, 156 assertions, 2 failures, 3060 / 13457 LOC (22.74%) covered.&lt;br /&gt;
; Unit tests : 18 tests, 18 assertions, 0 failures&lt;br /&gt;
; Functional tests : 87 tests, 138 assertions, 2 failures (reasons of failures can be found in &amp;quot;Possible Bugs&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
== Running Tests ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
Run &lt;br /&gt;
 rake test:prepare&lt;br /&gt;
before each action.&lt;br /&gt;
To run unit tests&lt;br /&gt;
 bundle exec ruby -I.:test -e &amp;quot;ARGV.each{|f| require f}&amp;quot; test/unit/team_test.rb test/unit/course_team_test.rb test/unit/assignment_team_test.rb test/unit/team_user_test.rb&lt;br /&gt;
To run functional tests&lt;br /&gt;
 bundle exec ruby -I.:test -e &amp;quot;ARGV.each{|f| require f}&amp;quot; test/functional/advertise_for_partner_controller_test.rb test/functional/teams_users_controller_test.rb&lt;br /&gt;
You can also run multiple tests&lt;br /&gt;
  bundle exec ruby -I.:test -e &amp;quot;ARGV.each{|f| require f}&amp;quot; test/functional/teams_users_controller_test.rb test/functional/advertise_for_partner_controller_test.rb test/unit/course_team_test.rb test/unit/assignment_team_test.rb test/unit/team_test.rb test/unit/team_user_test.rb&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb===&lt;br /&gt;
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.&lt;br /&gt;
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.&lt;br /&gt;
=== advertise_for_partner.rb ===&lt;br /&gt;
* This controller takes over the advertisement function from the student_team_controller, and make the class more RESTful. &lt;br /&gt;
* It seems like there has been a functional test, but the class name and set up looks like the other class. It may be necessary to re-run, and even re-write the test&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* This model defines the relationship between team object and other objects. It also has other methods to handle related functions about team operation&lt;br /&gt;
* There exists a unit test for team model, but there are only two test cases. Also, some of the methods under team.rb are duplicated, or either marked as not working. Further research may be required before starting to do the test.&lt;br /&gt;
=== assignment_team.rb &amp;amp; course_team.rb ===&lt;br /&gt;
* Both assignment_team class and course_team class are inherited from team class.&lt;br /&gt;
* These two classes have similar methods, which could be used to manage teams for assignment and course more effectively.&lt;br /&gt;
== Summary of Found Issues ==&lt;br /&gt;
=== Changes made to the class===&lt;br /&gt;
==== team.rb ==== &lt;br /&gt;
''Based on the discussion from the demo, the duplicated method was deleted instead of commented out''&lt;br /&gt;
* duplicated def get_participants was removed&lt;br /&gt;
** This is removed because the same method is defined again at line 20&lt;br /&gt;
* duplicated def self.generate_team_name() was removed&lt;br /&gt;
** This is removed because the same method is defined again at line 131&lt;br /&gt;
==== advertise_for_team_controller.rb ====&lt;br /&gt;
* def new was removed&lt;br /&gt;
** since it's empty, there is no need to keep the code there&lt;br /&gt;
&lt;br /&gt;
=== Possible Refactoring ===&lt;br /&gt;
==== team.rb ==== &lt;br /&gt;
* line 81 def self.create_node_object(name, parent_id)&lt;br /&gt;
** see the TODO at line 80, the method will not work.&lt;br /&gt;
=== advertise_for_team_controller.rb ===&lt;br /&gt;
* ''update'' should be ''edit'' (this is mentioned in the comments of code)&lt;br /&gt;
* ''edit'' should be reexamined since it is only assigning the team object&lt;br /&gt;
=== assignment_team.rb ===&lt;br /&gt;
* in &amp;quot;delete&amp;quot; method, before sign_up.each.destory, we need to make sure sign_up is not nil.&lt;br /&gt;
* in &amp;quot;email&amp;quot; method, a method named get_team_users is called but this method has no definition. We should define get_team_users somewhere or delete &amp;quot;email&amp;quot; method.&lt;br /&gt;
=== course_team.rb ===&lt;br /&gt;
* add_participant(course_id, user)method should belong to course rather than course_team. Delete this method.&lt;br /&gt;
* self.export_all_assignment_team_related_to_course(csv, parent_id, options)method should be deleted.&lt;br /&gt;
&lt;br /&gt;
=== Possible Bugs ===&lt;br /&gt;
==== team.rb ====&lt;br /&gt;
* def add_member(user, assignment_id) allow nil to be passed&lt;br /&gt;
** rails always raise runtime error when nil is passed. [[#unit/team_test.rb|Test: &amp;quot;add member for course should create teams user&amp;quot; ]]&lt;br /&gt;
* def randomize_all_by_parent passing wrong arguments&lt;br /&gt;
** The code is passing wrong arguments in line 124 for add_member, there should be 2 arguments. [[#unit/team_test.rb|Test: &amp;quot;randomize_all_by_parent&amp;quot; ]]&lt;br /&gt;
* def import_team_members passing wrong arguments&lt;br /&gt;
** it is calling add_member and passing nil for assignment_id, which will make rails raise error.[[#unit/team_test.rb|Test: &amp;quot;import team members successfully&amp;quot; ]]&lt;br /&gt;
==== assignment_team.rb ====&lt;br /&gt;
* def self.get_export_fields(options)&lt;br /&gt;
** when the option team_name =&amp;gt; false, the second element of the output array should be &amp;quot;Team members&amp;quot;. But from the test, it is &amp;quot;Assignment Name&amp;quot;. This is one failure from assignment_team_test.rb&lt;br /&gt;
* def add_participant(assignment_id, user)&lt;br /&gt;
** the AssignmentParticipant.count does not increase. This is another failure from assignment_team_test.rb.&lt;br /&gt;
==== teams_user.rb ====&lt;br /&gt;
* def delete(option)&lt;br /&gt;
** should not call ''team.delete'', it will cause recursion error&lt;br /&gt;
* def self.is_team_empty(team_id)&lt;br /&gt;
** rewrite this method without using ''length'' method, the ''length'' method will generate errors here&lt;br /&gt;
==== teams_users_controller.rb ====&lt;br /&gt;
* def delete_selected(options)&lt;br /&gt;
** the statement ''TeamsUser.find(item_id).first'' cannot work, since the method ''find'' will return an exact object, which cannot be applied ''first'' method&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
To set up our testing for the models and controllers, we need some fixtures to support. &lt;br /&gt;
Fixtures needed for corresponding classes are listed below&lt;br /&gt;
'''However, all of the fixtures are required to be in the fixutre folder, otherwise it will raise error.'''&lt;br /&gt;
&lt;br /&gt;
=== fixtures use in common ===&lt;br /&gt;
* teams.yml&lt;br /&gt;
* users.yml &lt;br /&gt;
* teams_users.yml&lt;br /&gt;
* courses.yml&lt;br /&gt;
* assignments.yml&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
* join_team_requests.yml&lt;br /&gt;
* participants.yml&lt;br /&gt;
* nodes.yml&lt;br /&gt;
* questions.yml&lt;br /&gt;
* signed_up_users.yml&lt;br /&gt;
&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_partner_controller.rb ===&lt;br /&gt;
[[File:Usecase_E1414_advertise.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Concerns for Test Cases ==&lt;br /&gt;
&lt;br /&gt;
=== functional/teams_users_controller_test.rb ===&lt;br /&gt;
[[File:TeamUsersStory.png]]&lt;br /&gt;
&lt;br /&gt;
Based on the user story of the teams_users_controller.rb, there are also several sub-scenarios for each method in the user story.&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== unit/teams_users_test.rb ===&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete to check if it could delete the team node and the team user&lt;br /&gt;
&lt;br /&gt;
* Remove_team&lt;br /&gt;
** Test Remove_team with valid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
* Is_team_empty&lt;br /&gt;
** Test Is_team_empty with empty team&lt;br /&gt;
** Test Is_team_empty with non-empty team&lt;br /&gt;
&lt;br /&gt;
* Add_member_to_invited_team&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
=== functional/advertise_for_partner_controller_test.rb ===&lt;br /&gt;
*  # test &amp;quot;test update advertisement fail&amp;quot; do&lt;br /&gt;
** should show flash for fail message when team.save fail, but there is no really a good way to fail team.save, so this is not implemented&lt;br /&gt;
&lt;br /&gt;
=== unit/team_test.rb ===&lt;br /&gt;
Most of test should be straightforward, so only the test with concerns will be listed below&lt;br /&gt;
*  test &amp;quot;get_participants from assignment team&amp;quot; do&lt;br /&gt;
** Please notice that this will actually call the get_participants under AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
*  test &amp;quot;generate_team_name&amp;quot; do&lt;br /&gt;
** Please notice that this method (self.generate_team_name)is modified&lt;br /&gt;
&lt;br /&gt;
*  test &amp;quot;add member for course should create teams user&amp;quot; do&lt;br /&gt;
** In the original code, it allow nil to be passed as parameter, and checks for assignment_id = nil, but rails will actually raise runtime error when nil is passed.&lt;br /&gt;
&lt;br /&gt;
*  #test &amp;quot;randomize_all_by_parent&amp;quot; do&lt;br /&gt;
** Commented out because the bug in the code make it raise error because assignment id not passed. (wrong argument)&lt;br /&gt;
&lt;br /&gt;
*  #test &amp;quot;import team members successfully&amp;quot; do&lt;br /&gt;
** problem: add_member are not passing correct assignment id in team.rb&lt;br /&gt;
&lt;br /&gt;
=== unit/assignment_team_test.rb ===&lt;br /&gt;
Because most of the tests are straightforward, only tests with concerns are listed.&lt;br /&gt;
* delete&lt;br /&gt;
** this method has bug. In the method, before sign_up.each.destory, we need to make sure sign_up is not nil. No test&lt;br /&gt;
* email&lt;br /&gt;
** this method has bug because there is no method named get_team_users. No test&lt;br /&gt;
&lt;br /&gt;
=== unit/course_team_test.rb ===&lt;br /&gt;
Only tests with concerns are listed.&lt;br /&gt;
*add_participant(course_id, user)&lt;br /&gt;
** this method should belong to course rather than course_team. This test may be not useful.&lt;br /&gt;
* self.export_all_assignment_team_related_to_course(csv, parent_id, options)&lt;br /&gt;
** this method should be deleted from course_team class. No test&lt;br /&gt;
&lt;br /&gt;
== Possible Refactoring ==&lt;br /&gt;
=== teams_participant.rb &amp;amp; teams_participants_controller.rb ===&lt;br /&gt;
* These two files are never used, no tests will cover them.&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers from our previous work to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
The first piece of code is from student_team_controller.rb. It tests if there is already a same team name when student8 want to create a team. The second piece of code is from teams_controller_test.rb. It tests if the team number decreases when instructor1 creates a new team for a course.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, several parameters are needed. Usually we use four parameters: First, the method we are requesting. Second, an hash of request parameters for the method. Third, an optional hash of session variables. Forth, an optional hash of flash values. If we do not want to pass in the optional hash, we can set it to nil as the first piece of code shows, or we can just leave it blank as the second piece of code shows.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Qjia2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84824</id>
		<title>CSC/ECE 517 Spring 2014/final doc updated qyx</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84824"/>
		<updated>2014-04-29T17:09:09Z</updated>

		<summary type="html">&lt;p&gt;Qjia2: /* Possible Bugs */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
== Introduction ==&lt;br /&gt;
This project will be an extension of our [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Spring_2014/oss_E1406_st previous E1406 project]. For the previous project, we did some refactoring and testing for the controllers related to teams. This time, we are going to reuse most of our test environment, but extend the tests to other team-related classes. We also expect to examine and report the code that may require refactoring.&lt;br /&gt;
&lt;br /&gt;
== Test Environment ==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
&lt;br /&gt;
=== Statistics ===&lt;br /&gt;
''Please note that the coverage generate by SimpleCov may be lower than expect due to the added fixtures.''&lt;br /&gt;
&lt;br /&gt;
; Overall (set of 6 tests) : 105 tests, 156 assertions, 2 failures, 3060 / 13457 LOC (22.74%) covered.&lt;br /&gt;
; Unit tests : 18 tests, 18 assertions, 0 failures&lt;br /&gt;
; Functional tests : 87 tests, 138 assertions, 2 failures (reasons of failures can be found in &amp;quot;Possible Bugs&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
== Running Tests ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
Run &lt;br /&gt;
 rake test:prepare&lt;br /&gt;
before each action.&lt;br /&gt;
To run unit tests&lt;br /&gt;
 bundle exec ruby -I.:test -e &amp;quot;ARGV.each{|f| require f}&amp;quot; test/unit/team_test.rb test/unit/course_team_test.rb test/unit/assignment_team_test.rb test/unit/team_user_test.rb&lt;br /&gt;
To run functional tests&lt;br /&gt;
 bundle exec ruby -I.:test -e &amp;quot;ARGV.each{|f| require f}&amp;quot; test/functional/advertise_for_partner_controller_test.rb test/functional/teams_users_controller_test.rb&lt;br /&gt;
You can also run multiple tests&lt;br /&gt;
  bundle exec ruby -I.:test -e &amp;quot;ARGV.each{|f| require f}&amp;quot; test/functional/teams_users_controller_test.rb test/functional/advertise_for_partner_controller_test.rb test/unit/course_team_test.rb test/unit/assignment_team_test.rb test/unit/team_test.rb test/unit/team_user_test.rb&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb===&lt;br /&gt;
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.&lt;br /&gt;
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.&lt;br /&gt;
=== advertise_for_partner.rb ===&lt;br /&gt;
* This controller takes over the advertisement function from the student_team_controller, and make the class more RESTful. &lt;br /&gt;
* It seems like there has been a functional test, but the class name and set up looks like the other class. It may be necessary to re-run, and even re-write the test&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* This model defines the relationship between team object and other objects. It also has other methods to handle related functions about team operation&lt;br /&gt;
* There exists a unit test for team model, but there are only two test cases. Also, some of the methods under team.rb are duplicated, or either marked as not working. Further research may be required before starting to do the test.&lt;br /&gt;
=== assignment_team.rb &amp;amp; course_team.rb ===&lt;br /&gt;
* Both assignment_team class and course_team class are inherited from team class.&lt;br /&gt;
* These two classes have similar methods, which could be used to manage teams for assignment and course more effectively.&lt;br /&gt;
== Summary of Found Issues ==&lt;br /&gt;
=== Changes made to the class===&lt;br /&gt;
==== team.rb ==== &lt;br /&gt;
''Based on the discussion from the demo, the duplicated method was deleted instead of commented out''&lt;br /&gt;
* duplicated def get_participants was removed&lt;br /&gt;
** This is removed because the same method is defined again at line 20&lt;br /&gt;
* duplicated def self.generate_team_name() was removed&lt;br /&gt;
** This is removed because the same method is defined again at line 131&lt;br /&gt;
==== advertise_for_team_controller.rb ====&lt;br /&gt;
* def new was removed&lt;br /&gt;
** since it's empty, there is no need to keep the code there&lt;br /&gt;
&lt;br /&gt;
=== Possible Refactoring ===&lt;br /&gt;
==== team.rb ==== &lt;br /&gt;
* line 81 def self.create_node_object(name, parent_id)&lt;br /&gt;
** see the TODO at line 80, the method will not work.&lt;br /&gt;
=== advertise_for_team_controller.rb ===&lt;br /&gt;
* ''update'' should be ''edit'' (this is mentioned in the comments of code)&lt;br /&gt;
* ''edit'' should be reexamined since it is only assigning the team object&lt;br /&gt;
=== assignment_team.rb ===&lt;br /&gt;
* in &amp;quot;delete&amp;quot; method, before sign_up.each.destory, we need to make sure sign_up is not nil.&lt;br /&gt;
* in &amp;quot;email&amp;quot; method, a method named get_team_users is called but this method has no definition. We should define get_team_users somewhere or delete &amp;quot;email&amp;quot; method.&lt;br /&gt;
=== course_team.rb ===&lt;br /&gt;
* add_participant(course_id, user)method should belong to course rather than course_team. Delete this method.&lt;br /&gt;
* self.export_all_assignment_team_related_to_course(csv, parent_id, options)method should be deleted.&lt;br /&gt;
&lt;br /&gt;
=== Possible Bugs ===&lt;br /&gt;
==== team.rb ====&lt;br /&gt;
* def add_member(user, assignment_id) allow nil to be passed&lt;br /&gt;
** rails always raise runtime error when nil is passed. [[#unit/team_test.rb|Test: &amp;quot;add member for course should create teams user&amp;quot; ]]&lt;br /&gt;
* def randomize_all_by_parent passing wrong arguments&lt;br /&gt;
** The code is passing wrong arguments in line 124 for add_member, there should be 2 arguments. [[#unit/team_test.rb|Test: &amp;quot;randomize_all_by_parent&amp;quot; ]]&lt;br /&gt;
* def import_team_members passing wrong arguments&lt;br /&gt;
** it is calling add_member and passing nil for assignment_id, which will make rails raise error.[[#unit/team_test.rb|Test: &amp;quot;import team members successfully&amp;quot; ]]&lt;br /&gt;
==== assignment_team.rb ====&lt;br /&gt;
* def self.get_export_fields(options)&lt;br /&gt;
** when the option team_name =&amp;gt; false, the second element of the output array should be &amp;quot;Team members&amp;quot;. But from the test, it is &amp;quot;Assignment Name&amp;quot;. This is one failure from assignment_team_test.rb&lt;br /&gt;
* def add_participant(assignment_id, user)&lt;br /&gt;
** the AssignmentParticipant.count does not increase. This is another failure from assignment_team_test.rb.&lt;br /&gt;
==== teams_user.rb ====&lt;br /&gt;
* def delete(option)&lt;br /&gt;
** should not call ''team.delete'', it will cause recursion error&lt;br /&gt;
* def self.is_team_empty(team_id)&lt;br /&gt;
** rewrite this method without using ''length'' method, the ''length'' method will generate errors here&lt;br /&gt;
==== teams_users_controller.rb ====&lt;br /&gt;
* def delete_selected(options)&lt;br /&gt;
** the statement ''TeamsUser.find(item_id).first'' cannot work, since the method ''find'' will return an exact object, which cannot be applied ''first'' method&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
To set up our testing for the models and controllers, we need some fixtures to support. &lt;br /&gt;
Fixtures needed for corresponding classes are listed below&lt;br /&gt;
'''However, all of the fixtures are required to be in the fixutre folder, otherwise it will raise error.'''&lt;br /&gt;
&lt;br /&gt;
=== fixtures use in common ===&lt;br /&gt;
* teams.yml&lt;br /&gt;
* users.yml &lt;br /&gt;
* teams_users.yml&lt;br /&gt;
* courses.yml&lt;br /&gt;
* assignments.yml&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
* join_team_requests.yml&lt;br /&gt;
* participants.yml&lt;br /&gt;
* nodes.yml&lt;br /&gt;
* questions.yml&lt;br /&gt;
* signed_up_users.yml&lt;br /&gt;
&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_partner_controller.rb ===&lt;br /&gt;
[[File:Usecase_E1414_advertise.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Concerns for Test Cases ==&lt;br /&gt;
&lt;br /&gt;
=== functional/teams_users_controller_test.rb ===&lt;br /&gt;
[[File:TeamUsersStory.png]]&lt;br /&gt;
&lt;br /&gt;
Based on the user story of the teams_users_controller.rb, there are also several sub-scenarios for each method in the user story.&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== unit/teams_users_test.rb ===&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete to check if it could delete the team node and the team user&lt;br /&gt;
&lt;br /&gt;
* Remove_team&lt;br /&gt;
** Test Remove_team with valid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
* Is_team_empty&lt;br /&gt;
** Test Is_team_empty with empty team&lt;br /&gt;
** Test Is_team_empty with non-empty team&lt;br /&gt;
&lt;br /&gt;
* Add_member_to_invited_team&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
=== functional/advertise_for_partner_controller_test.rb ===&lt;br /&gt;
*  # test &amp;quot;test update advertisement fail&amp;quot; do&lt;br /&gt;
** should show flash for fail message when team.save fail, but there is no really a good way to fail team.save, so this is not implemented&lt;br /&gt;
&lt;br /&gt;
=== unit/team_test.rb ===&lt;br /&gt;
Most of test should be straightforward, so only the test with concerns will be listed below&lt;br /&gt;
*  test &amp;quot;get_participants from assignment team&amp;quot; do&lt;br /&gt;
** Please notice that this will actually call the get_participants under AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
*  test &amp;quot;generate_team_name&amp;quot; do&lt;br /&gt;
** Please notice that this method (self.generate_team_name)is modified&lt;br /&gt;
&lt;br /&gt;
*  test &amp;quot;add member for course should create teams user&amp;quot; do&lt;br /&gt;
** In the original code, it allow nil to be passed as parameter, and checks for assignment_id = nil, but rails will actually raise runtime error when nil is passed.&lt;br /&gt;
&lt;br /&gt;
*  #test &amp;quot;randomize_all_by_parent&amp;quot; do&lt;br /&gt;
** Commented out because the bug in the code make it raise error because assignment id not passed. (wrong argument)&lt;br /&gt;
&lt;br /&gt;
*  #test &amp;quot;import team members successfully&amp;quot; do&lt;br /&gt;
** problem: add_member are not passing correct assignment id in team.rb&lt;br /&gt;
&lt;br /&gt;
=== unit/assignment_team_test.rb ===&lt;br /&gt;
Because most of the tests are straightforward, only tests with concerns are listed.&lt;br /&gt;
* delete&lt;br /&gt;
** this method has bug. In the method, before sign_up.each.destory, we need to make sure sign_up is not nil. No test&lt;br /&gt;
* email&lt;br /&gt;
** this method has bug because there is no method named get_team_users. No test&lt;br /&gt;
&lt;br /&gt;
=== unit/course_team_test.rb ===&lt;br /&gt;
Only tests with concerns are listed.&lt;br /&gt;
*add_participant(course_id, user)&lt;br /&gt;
** this method should belong to course rather than course_team. This test may be not useful.&lt;br /&gt;
* self.export_all_assignment_team_related_to_course(csv, parent_id, options)&lt;br /&gt;
** this method should be deleted from course_team class. No test&lt;br /&gt;
&lt;br /&gt;
== Possible Refactoring ==&lt;br /&gt;
=== teams_participant.rb &amp;amp; teams_participants_controller.rb ===&lt;br /&gt;
* These two files are never used, no tests will cover them.&lt;br /&gt;
&lt;br /&gt;
=== teams_user.rb ===&lt;br /&gt;
* In ''delete'' method, the statements about ''team.delete'' should be commented out due to the recursion it causes.&lt;br /&gt;
* ''elf.is_team_empty'' method is rewritten since the original code will cause fatal error.&lt;br /&gt;
&lt;br /&gt;
=== teams_users_controller.rb ===&lt;br /&gt;
* ''delete_select'' method will not work since the params are not in accordance with the method called inside.&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers from our previous work to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
The first piece of code is from student_team_controller.rb. It tests if there is already a same team name when student8 want to create a team. The second piece of code is from teams_controller_test.rb. It tests if the team number decreases when instructor1 creates a new team for a course.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, several parameters are needed. Usually we use four parameters: First, the method we are requesting. Second, an hash of request parameters for the method. Third, an optional hash of session variables. Forth, an optional hash of flash values. If we do not want to pass in the optional hash, we can set it to nil as the first piece of code shows, or we can just leave it blank as the second piece of code shows.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Qjia2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84736</id>
		<title>CSC/ECE 517 Spring 2014/final doc updated qyx</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84736"/>
		<updated>2014-04-25T00:11:32Z</updated>

		<summary type="html">&lt;p&gt;Qjia2: /* Possible Refacotring */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
== Introduction ==&lt;br /&gt;
This project will be an extension of our [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Spring_2014/oss_E1406_st previous E1406 project]. For the previous project, we did some refactoring and testing for the controllers related to teams. This time, we are going to reuse most of our test environment, but extend the tests to other team-related classes. We also expect to examine and report the code that may require refactoring.&lt;br /&gt;
== Test Environment ==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb===&lt;br /&gt;
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.&lt;br /&gt;
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.&lt;br /&gt;
=== advertise_for_partner.rb ===&lt;br /&gt;
* This controller takes over the advertisement function from the student_team_controller, and make the class more RESTful. &lt;br /&gt;
* It seems like there has been a functional test, but the class name and set up looks like the other class. It may be necessary to re-run, and even re-write the test&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* This model defines the relationship between team object and other objects. It also has other methods to handle related functions about team operation&lt;br /&gt;
* There exists a unit test for team model, but there are only two test cases. Also, some of the methods under team.rb are duplicated, or either marked as not working. Further research may be required before starting to do the test.&lt;br /&gt;
=== assignment_team.rb &amp;amp; course_team.rb ===&lt;br /&gt;
* Both assignment_team class and course_team class are inherited from team class.&lt;br /&gt;
* These two classes have similar methods, which could be used to manage teams for assignment and course more effectively.&lt;br /&gt;
== Changes made to original classes ==&lt;br /&gt;
=== team.rb === &lt;br /&gt;
* line 10 def get_participants removed&lt;br /&gt;
** This is commented out because the same method is defined again at line 26&lt;br /&gt;
* line 38 def self.generate_team_name() removed&lt;br /&gt;
** This is commented out because the same method is defined again at line 150&lt;br /&gt;
* line 100 def self.create_node_object(name, parent_id)&lt;br /&gt;
** see the TODO at line 99, the method will not work.&lt;br /&gt;
&lt;br /&gt;
== Test Classes ==&lt;br /&gt;
=== app/models/teams_users.rb===&lt;br /&gt;
The teams_users.rb is a model belonging to both users and teams. It is used when a user is added to a team.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_users_controller.rb===&lt;br /&gt;
The teams_users_controller support team member management for instructor/TA accounts&lt;br /&gt;
Instruction/TA can:&lt;br /&gt;
* get a user name by inputting part of the name&lt;br /&gt;
* list team members of a team &lt;br /&gt;
* add a user to a team&lt;br /&gt;
* remove a team member from a team&lt;br /&gt;
* remove all members belonging to an item&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/advertise_for_partners_controller.rb ===&lt;br /&gt;
The advertise_for_partners_controller work with the student_team_controllers, allowing student manage advertisement for their teams.&lt;br /&gt;
&lt;br /&gt;
A student can:&lt;br /&gt;
* create a new advertisement for the team&lt;br /&gt;
* edit the advertisement content&lt;br /&gt;
* remove advertisement record from the table for the specific team&lt;br /&gt;
&lt;br /&gt;
=== app/models/team.rb ===&lt;br /&gt;
The “team” object represents a team that consists students who are either participants of course or assignment.&lt;br /&gt;
a team will response to the request on: &lt;br /&gt;
&lt;br /&gt;
* get_participants : get participant in the team&lt;br /&gt;
* delete : delete a team member in the team&lt;br /&gt;
* get_node_type : will return “TeamNode”&lt;br /&gt;
* get_author_name : will return team’s name&lt;br /&gt;
* generate_team_name() : serialize the automatically generated team name (e.g. team 1, team 2, etc.)&lt;br /&gt;
* get_possible_team_members(name) : find a team member by name&lt;br /&gt;
* has_user(user : find a team member by user object&lt;br /&gt;
* add_member(user, assignment_id) : add a user to an assignment team&lt;br /&gt;
* copy_members(new_team) : copy current member in the team to the new team&lt;br /&gt;
* create_node_object(name, parent_id) : ‘’there is a TODO on this method indicated that this is not working’’ &lt;br /&gt;
* check_for_exisiting(parent, name, team_type) : check if the team name under the same assignment or course is in use.&lt;br /&gt;
* delete_all_by_parent(parent) : delete all teams under the same course/assignment&lt;br /&gt;
* randomize_all_by_parent(parent, team_type, team_size) : randomly assign team members&lt;br /&gt;
* generate_team_name(teamnameprefix) : generate team name with prefix (e.g. prefix_Team1) &lt;br /&gt;
* import_team_members(starting_index, row) : import user from specific index of users and length&lt;br /&gt;
&lt;br /&gt;
=== app/unit/assignment_team.rb ===&lt;br /&gt;
* includes?(participant): check if this assignment team include this participant&lt;br /&gt;
* assign_reviewer(reviewer): assign a reviewer for this assignment team&lt;br /&gt;
* reviewed_by?(reviewer)：check if this assignment team is reviewed by this reviewer&lt;br /&gt;
* topic: get the topic picked up by this team&lt;br /&gt;
* has_submissions?: check if this team submitted work or not&lt;br /&gt;
* reviewed_contributor?(contributor)&lt;br /&gt;
* participants: get all the participants&lt;br /&gt;
* delete: delete the signed up users&lt;br /&gt;
* self.get_first_member(team_id): get the first participant&lt;br /&gt;
* get_hyperlinks&lt;br /&gt;
* get_path&lt;br /&gt;
* get_submitted_files&lt;br /&gt;
* get_review_map_type: return TeamReviewResponseMap&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates): handle duplicate team in different cases&lt;br /&gt;
* self.import(row,session,assignment_id,options): import team members to a exist team or a new team&lt;br /&gt;
* email： get fist team user's email&lt;br /&gt;
* get_participant_type: return AssignmentParticipant&lt;br /&gt;
* get_parent_model：return Assignment&lt;br /&gt;
* fullname&lt;br /&gt;
* get_participants&lt;br /&gt;
* copy(course_id): copy a team from course team&lt;br /&gt;
* add_participant(assignment_id, user): add participant to AssignmentParticipant&lt;br /&gt;
* assignment&lt;br /&gt;
* get_scores(questions): return a hash of scores that the team has received for the questions&lt;br /&gt;
* self.get_team(participant): get this participant's team&lt;br /&gt;
* self.export(csv, parent_id, options): export assignment and team members&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
* self.remove_team_by_id(id): Remove a team given the team id&lt;br /&gt;
&lt;br /&gt;
=== app/unit/course_team.rb ===&lt;br /&gt;
* get_participant_type: return CourseParticipant&lt;br /&gt;
* get_parent_model：return Course&lt;br /&gt;
* get_node_type: return TeamNode&lt;br /&gt;
* assignment_id: return nil&lt;br /&gt;
* copy(assignment_id): copy a team from assignment team&lt;br /&gt;
* add_participant(course_id, user): add a user to a course. Note: this is deprecated because the functionality belongs to course&lt;br /&gt;
* export_participants: export the participants of a course team&lt;br /&gt;
* export(team_name_only): export team name, participants and course&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates): handle duplicate team in different cases&lt;br /&gt;
* self.import(row,session,assignment_id,options): import team members to a exist team or a new team&lt;br /&gt;
* self.export(csv, parent_id, options): export course and team members&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
* self.export_all_assignment_team_related_to_course(csv, parent_id, options): this method is deprecated&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
To set up our testing for the models and controllers, we need some fixtures to support. &lt;br /&gt;
Fixtures needed for corresponding classes are listed below&lt;br /&gt;
'''However, all of the fixtures are required to be in the fixutre folder, otherwise it will raise error.'''&lt;br /&gt;
&lt;br /&gt;
=== fixtures use in common ===&lt;br /&gt;
* teams.yml&lt;br /&gt;
* users.yml &lt;br /&gt;
* teams_users.yml&lt;br /&gt;
* courses.yml&lt;br /&gt;
* assignments.yml&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
* join_team_requests.yml&lt;br /&gt;
* participants.yml&lt;br /&gt;
* nodes.yml&lt;br /&gt;
* questions.yml&lt;br /&gt;
* signed_up_users.yml&lt;br /&gt;
&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_partner_controller.rb ===&lt;br /&gt;
[[File:Usecase_E1414_advertise.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Testing Scenarios ==&lt;br /&gt;
&lt;br /&gt;
=== functional/teams_users_controller_test.rb ===&lt;br /&gt;
[[File:TeamUsersStory.png]]&lt;br /&gt;
&lt;br /&gt;
Based on the user story of the teams_users_controller.rb, there are also several sub-scenarios for each method in the user story.&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== unit/teams_users_test.rb ===&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete to check if it could delete the team node and the team user&lt;br /&gt;
&lt;br /&gt;
* Remove_team&lt;br /&gt;
** Test Remove_team with valid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
* Is_team_empty&lt;br /&gt;
** Test Is_team_empty with empty team&lt;br /&gt;
** Test Is_team_empty with non-empty team&lt;br /&gt;
&lt;br /&gt;
* Add_member_to_invited_team&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
=== functional/advertise_for_partner_controller_test.rb ===&lt;br /&gt;
* test &amp;quot;test remove advertisement should set advertise_for_partner false&amp;quot; do&lt;br /&gt;
* test &amp;quot;test remove advertisement should remove advertisement comments&amp;quot; do&lt;br /&gt;
* test &amp;quot;test remove advertisement should redirect to view&amp;quot; do&lt;br /&gt;
* test &amp;quot;test create advertisement should set advertise_for_partner true&amp;quot; do&lt;br /&gt;
*  test &amp;quot;test create advertisement should set comment for advertisement&amp;quot; do&lt;br /&gt;
*  test &amp;quot;test create advertisement should redirect to view&amp;quot; do&lt;br /&gt;
*  test &amp;quot;test update advertisement successfully should show notice&amp;quot; do&lt;br /&gt;
*  test &amp;quot;test update advertisement successfully should change comment&amp;quot; do&lt;br /&gt;
*  test &amp;quot;test update advertisement successfully should redirect to view&amp;quot; do&lt;br /&gt;
*  # test &amp;quot;test update advertisement fail&amp;quot; do&lt;br /&gt;
** should show flash for fail message when team.save fail, but there is no really a good way to fail team.save, so this is not implemented&lt;br /&gt;
*  test &amp;quot;test edit advertisement&amp;quot; do&lt;br /&gt;
** only assign team&lt;br /&gt;
&lt;br /&gt;
=== unit/team_test.rb ===&lt;br /&gt;
*  test &amp;quot;add_team&amp;quot; do&lt;br /&gt;
*  test &amp;quot;delete should destroy the team&amp;quot; do&lt;br /&gt;
*  test &amp;quot;delete should remove all teams user&amp;quot; do&lt;br /&gt;
*  test &amp;quot;delete should remove all team node&amp;quot; do&lt;br /&gt;
*  test &amp;quot;get_participants from assignment team&amp;quot; do&lt;br /&gt;
** Please notice that this will actually call the get_participants under AssignmentTeam&lt;br /&gt;
*  test &amp;quot;get_participants from course team&amp;quot; do&lt;br /&gt;
*  test &amp;quot;get_node_type&amp;quot; do&lt;br /&gt;
*  test &amp;quot;get_author_name&amp;quot; do&lt;br /&gt;
*  test &amp;quot;generate_team_name&amp;quot; do&lt;br /&gt;
** Please notice that this method (self.generate_team_name)is modified&lt;br /&gt;
*  test &amp;quot;generate_team_name for existed prefix&amp;quot; do&lt;br /&gt;
*  test &amp;quot;get_possible_team_members&amp;quot; do&lt;br /&gt;
*  test &amp;quot;has_user&amp;quot; do&lt;br /&gt;
*  test &amp;quot;do not has_user&amp;quot; do&lt;br /&gt;
*  test &amp;quot;add member already in team&amp;quot; do&lt;br /&gt;
*  test &amp;quot;add member for course should create teams user&amp;quot; do&lt;br /&gt;
** In the original code, it allow nil to be passed as parameter, and checks for assignment.id = nil, but rails will actually raise runtime error when nil is passed.&lt;br /&gt;
*  test &amp;quot;add member for course should create teams user node&amp;quot; do&lt;br /&gt;
*  test &amp;quot;add member to assignment team successfully&amp;quot; do&lt;br /&gt;
*  test &amp;quot;add member to full assignment team should fail&amp;quot; do&lt;br /&gt;
*  test &amp;quot;copy_members from assignment team&amp;quot; do&lt;br /&gt;
*  test &amp;quot;copy_members from course team&amp;quot; do&lt;br /&gt;
*  test &amp;quot;check_for_existing for AssignmentTeam&amp;quot; do&lt;br /&gt;
*  test &amp;quot;check_for_existing for existed AssignmentTeam should raise error&amp;quot; do&lt;br /&gt;
*  test &amp;quot;delete all by parent should delete teams&amp;quot; do&lt;br /&gt;
*  test &amp;quot;delete all by parent will not fail when no teams found&amp;quot; do&lt;br /&gt;
*  #test &amp;quot;randomize_all_by_parent&amp;quot; do&lt;br /&gt;
** Commented out because the bug in the code make it raise error because assignment id not passed. (wrong argument)&lt;br /&gt;
*  test &amp;quot;import team members for user not existed should raise error&amp;quot; do&lt;br /&gt;
*  #test &amp;quot;import team members successfully&amp;quot; do&lt;br /&gt;
** problem: add_member are not passing correct assignment id at line 169 in team.rb&lt;br /&gt;
&lt;br /&gt;
=== unit/assignment_team_test.rb ===&lt;br /&gt;
* includes?(participant)&lt;br /&gt;
** test one assignment team include a participant return true&lt;br /&gt;
* assign_reviewer(reviewer)&lt;br /&gt;
** assign a reviewer for this assignment team, and TeamReviewResponseMap.count increases&lt;br /&gt;
* reviewed_by?(reviewer)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* has_submissions?&lt;br /&gt;
** test one team has a submission return true&lt;br /&gt;
* reviewed_contributor?(contributor)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* participants&lt;br /&gt;
** participants are not nil&lt;br /&gt;
* delete&lt;br /&gt;
** this method has bug. No test&lt;br /&gt;
* self.get_first_member(team_id)&lt;br /&gt;
** test first menber not nil&lt;br /&gt;
* get_hyperlinks&lt;br /&gt;
** test hyperlinks are not nil&lt;br /&gt;
* get_path&lt;br /&gt;
** test path is not nil&lt;br /&gt;
* get_submitted_files&lt;br /&gt;
** submitted_file must be empty, expect nil&lt;br /&gt;
* get_review_map_type&lt;br /&gt;
** return TeamReviewResponseMap&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates)&lt;br /&gt;
** test in different cases(team is nil, option is &amp;quot;ignore&amp;quot;, option is &amp;quot;rename&amp;quot;)&lt;br /&gt;
* self.import(row,session,assignment_id,options)&lt;br /&gt;
** test in different cases(argument error, has_column_name is true, has_column_name is false)&lt;br /&gt;
* email&lt;br /&gt;
** this method has bug because there is no method named get_team_users. No test&lt;br /&gt;
* get_participant_type&lt;br /&gt;
** return AssignmentParticipant&lt;br /&gt;
* get_parent_model&lt;br /&gt;
** return Assignment&lt;br /&gt;
* fullname&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_participants&lt;br /&gt;
** test the participants are not nil&lt;br /&gt;
* copy(course_id)&lt;br /&gt;
** TeamUserNode.count and TeamsUser.count increase&lt;br /&gt;
* add_participant(assignment_id, user)&lt;br /&gt;
** AssignmentParticipant.count increases&lt;br /&gt;
* assignment&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_scores(questions)&lt;br /&gt;
** return output's total score is not nil and the assignment team is what we expect&lt;br /&gt;
* self.get_team(participant)&lt;br /&gt;
** return team is what we expect&lt;br /&gt;
* self.export(csv, parent_id, options)&lt;br /&gt;
** test in different cases(team_name is true, team_name is false)&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
** test if the fields' name is right&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
** assignent team and team node are not nil&lt;br /&gt;
* self.remove_team_by_id(id)&lt;br /&gt;
** check the removed team cannot be found in AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
=== unit/course_team_test.rb ===&lt;br /&gt;
Because most of the methods in course_team.rb are similar with that in assignment_team.rb if they have the same name. So I skip the same name method. Take the test/unit/course_team_test.rb as a reference.&lt;br /&gt;
* self.export_all_assignment_team_related_to_course(csv, parent_id, options)&lt;br /&gt;
** this method should be deleted here. No test&lt;br /&gt;
&lt;br /&gt;
== Possible Refacotring ==&lt;br /&gt;
=== advertise_for_team_controller.rb ===&lt;br /&gt;
* ''update'' should be ''edit'' (this is mentioned in the comments of code)&lt;br /&gt;
* ''edit'' should be reexamined since it is only retrieving the team object&lt;br /&gt;
* ''new'' is empty, so it should be removed&lt;br /&gt;
&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* There are two ''def get_participants'', the second one overwritten the first one, so the first one should be deleted.&lt;br /&gt;
&lt;br /&gt;
=== teams_participant.rb &amp;amp; teams_participants_controller.rb ===&lt;br /&gt;
* These two files are never used, no tests will cover them.&lt;br /&gt;
&lt;br /&gt;
=== teams_user.rb ===&lt;br /&gt;
* In ''delete'' method, the statements about ''team.delete'' should be commented out due to the recursion it causes.&lt;br /&gt;
* ''elf.is_team_empty'' method is rewritten since the original code will cause fatal error.&lt;br /&gt;
&lt;br /&gt;
=== teams_users_controller.rb ===&lt;br /&gt;
* ''delete_select'' method will not work since the params are not in accordance with the method called inside.&lt;br /&gt;
&lt;br /&gt;
== Running Tests ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
To see the result of tests, run &lt;br /&gt;
 rake test TEST=test/unit/&amp;lt;filename&amp;gt; # for models&lt;br /&gt;
and &lt;br /&gt;
 rake test TEST=test/functional/&amp;lt;filename&amp;gt; # for controllers&lt;br /&gt;
&lt;br /&gt;
You can also run multiple tests&lt;br /&gt;
  rake test:prepare&lt;br /&gt;
  bundle exec ruby -I.:test -e &amp;quot;ARGV.each{|f| require f}&amp;quot; test/functional/teams_users_controller_test.rb test/functional/advertise_for_partner_controller_test.rb test/unit/course_team_test.rb test/unit/assignment_team_test.rb test/unit/team_test.rb test/unit/team_user_test.rb&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers from our previous work to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
The first piece of code is from student_team_controller.rb. It tests if there is already a same team name when student8 want to create a team. The second piece of code is from teams_controller_test.rb. It tests if the team number decreases when instructor1 creates a new team for a course.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, several parameters are needed. Usually we use four parameters: First, the method we are requesting. Second, an hash of request parameters for the method. Third, an optional hash of session variables. Forth, an optional hash of flash values. If we do not want to pass in the optional hash, we can set it to nil as the first piece of code shows, or we can just leave it blank as the second piece of code shows.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Qjia2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1414_st&amp;diff=84372</id>
		<title>CSC/ECE 517 Spring 2014/oss E1414 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1414_st&amp;diff=84372"/>
		<updated>2014-04-09T23:35:56Z</updated>

		<summary type="html">&lt;p&gt;Qjia2: /* teams_users.rb &amp;amp; teams_users_controller.rb */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
== Introduction ==&lt;br /&gt;
This project will be an extension of our [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Spring_2014/oss_E1406_st previous E1406 project]. For the previous project, we did some refactoring and testing for the controllers related to teams. This time, we are going to reuse most of our test environment, but extend the tests to other team-related classes. We also expect to examine and report the code that may require refactoring.&lt;br /&gt;
== Test Environment ==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb===&lt;br /&gt;
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.&lt;br /&gt;
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.&lt;br /&gt;
=== teams_participant.rb &amp;amp; teams_participant_controller.rb===&lt;br /&gt;
* teams_participant.rb and teams_participant_controller.rb are used to manage the participants of teams.&lt;br /&gt;
* There is no functional test for teams_participant_controller.rb and unit test for teams_participant.rb in the current version of expertiza codes.&lt;br /&gt;
=== advertise_for_partner.rb ===&lt;br /&gt;
* This controller takes over the advertisement function from the student_team_controller, and make the class more RESTful. &lt;br /&gt;
* It seems like there has been a functional test, but the class name and set up looks like the other class. It may be necessary to re-run, and even re-write the test&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* This model defines the relationship between team object and other objects. It also has other methods to handle related functions about team operation&lt;br /&gt;
* There exists a unit test for team model, but there are only two test cases. Also, some of the methods under team.rb are duplicated, or either marked as not working. Further research may be required before starting to do the test.&lt;br /&gt;
&lt;br /&gt;
==Classes==&lt;br /&gt;
=== app/models/teams_users.rb===&lt;br /&gt;
The teams_users.rb is a model belonging to both users and teams. It is used when a user is added to a team.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_users_controller.rb===&lt;br /&gt;
The teams_users_controller support team member management for instructor/TA accounts&lt;br /&gt;
Instruction/TA can:&lt;br /&gt;
* get a user name by inputting part of the name&lt;br /&gt;
* list team members of a team &lt;br /&gt;
* add a user to a team&lt;br /&gt;
* remove a team member from a team&lt;br /&gt;
* remove all members belonging to an item&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/advertise_for_partners_controller.rb ===&lt;br /&gt;
The advertise_for_partners_controller work with the student_team_controllers, allowing student manage advertisement for their teams.&lt;br /&gt;
&lt;br /&gt;
A student can:&lt;br /&gt;
* create a new advertisement for the team&lt;br /&gt;
* edit the advertisement content&lt;br /&gt;
* remove advertisement record from the table for the specific team&lt;br /&gt;
&lt;br /&gt;
=== app/models/teams_participant.rb===&lt;br /&gt;
The teams_participant.rb is a model belonging to both users and teams. It is used when a team participant is created, listed or deleted.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_participant_controller.rb===&lt;br /&gt;
The teams_participant_controller support team participants management so the team participant:&lt;br /&gt;
* get a participant name by inputting part of the name&lt;br /&gt;
* list team participants of a team &lt;br /&gt;
* add a participant to a team&lt;br /&gt;
* remove a selected team participant from a team&lt;br /&gt;
* remove all team participants belonging to an item&lt;br /&gt;
&lt;br /&gt;
=== app/models/team.rb ===&lt;br /&gt;
The “team” object represents a team that consists students who are either participants of course or assignment.&lt;br /&gt;
a team will response to the request on: &lt;br /&gt;
&lt;br /&gt;
;get_participants : get participant in the team&lt;br /&gt;
;delete : delete a team member in the team&lt;br /&gt;
;get_node_type : will return “TeamNode”&lt;br /&gt;
;get_author_name : will return team’s name&lt;br /&gt;
;generate_team_name() : serialize the automatically generated team name (e.g. team 1, team 2, etc.)&lt;br /&gt;
;get_possible_team_members(name) : find a team member by name&lt;br /&gt;
;has_user(user : find a team member by user object&lt;br /&gt;
;add_member(user, assignment_id) : add a user to an assignment team&lt;br /&gt;
;copy_members(new_team) : copy current member in the team to the new team&lt;br /&gt;
;create_node_object(name, parent_id) : ‘’there is a TODO on this method indicated that this is not working’’ &lt;br /&gt;
;check_for_exisiting(parent, name, team_type) : check if the team name under the same assignment or course is in use.&lt;br /&gt;
;Delete_all_by_parent(parent) : delete all teams under the same course/assignment&lt;br /&gt;
;Randomize_all_by_parent(parent, team_type, team_size) : randomly assign team members&lt;br /&gt;
;generate_team_name(teamnameprefix) : generate team name with prefix (e.g. prefix_Team1) &lt;br /&gt;
;import_team_members(starting_index, row) : import user from specific index of users and length&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
To set up our testing for the models and controllers, we need some fixtures to support. &lt;br /&gt;
Fixtures needed for corresponding classes are listed below&lt;br /&gt;
&lt;br /&gt;
=== fixtures use in common ===&lt;br /&gt;
* teams.yml&lt;br /&gt;
* users.yml &lt;br /&gt;
* teams_users.yml&lt;br /&gt;
* courses.yml&lt;br /&gt;
* assignments.yml&lt;br /&gt;
&lt;br /&gt;
=== teams_participant.rb &amp;amp; teams_participant_controller.rb ===&lt;br /&gt;
Besides the above fixtures, we also need the following fixrure&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
&lt;br /&gt;
=== teams.rb ===&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
* join_team_requests.yml&lt;br /&gt;
* participants.yml&lt;br /&gt;
* nodes.yml&lt;br /&gt;
&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
&lt;br /&gt;
=== teams_participant_controller.rb ===&lt;br /&gt;
[[File:Usercase.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_partner_controller.rb ===&lt;br /&gt;
[[File:Usecase_E1414_advertise.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Testing Scenarios ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb ===&lt;br /&gt;
[[File:TeamUsersStory.png]]&lt;br /&gt;
&lt;br /&gt;
Based on the user story of the teams_users_controller.rb, there are also several sub-scenarios for each method in the user story.&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
For the methods in teams_user.rb, the scenarios would be like the following:&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete to check if it could delete the team node and the team user&lt;br /&gt;
&lt;br /&gt;
* Remove_team&lt;br /&gt;
** Test Remove_team with valid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
* Is_team_empty&lt;br /&gt;
** Test Is_team_empty with empty team&lt;br /&gt;
** Test Is_team_empty with non-empty team&lt;br /&gt;
&lt;br /&gt;
* Add_member_to_invited_team&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
=== teams_participant.rb &amp;amp; teams_participant_controller.rb ===&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_partner_controller.rb ===&lt;br /&gt;
* remove&lt;br /&gt;
** test remove with valid user id&lt;br /&gt;
** test remove with invalid user id&lt;br /&gt;
&lt;br /&gt;
* create&lt;br /&gt;
** test create with valid user id&lt;br /&gt;
** test create with invalid user id&lt;br /&gt;
&lt;br /&gt;
* update&lt;br /&gt;
** test update with invalid id&lt;br /&gt;
** test update success&lt;br /&gt;
** test update fail (should remain the same)&lt;br /&gt;
&lt;br /&gt;
* edit&lt;br /&gt;
** test edit&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* get participants&lt;br /&gt;
** test get participants&lt;br /&gt;
&lt;br /&gt;
* delete&lt;br /&gt;
** test delete with team node&lt;br /&gt;
** test delete without team node&lt;br /&gt;
&lt;br /&gt;
* get_node_type &lt;br /&gt;
** test get node type&lt;br /&gt;
&lt;br /&gt;
* get_author_name&lt;br /&gt;
** test author name&lt;br /&gt;
&lt;br /&gt;
* generate_team_name() &lt;br /&gt;
** test generate team name from zero&lt;br /&gt;
** test generate team name from one&lt;br /&gt;
&lt;br /&gt;
* get_possible_team_members(name)&lt;br /&gt;
** test get possible team members by exact name&lt;br /&gt;
** test get possible team members by similar name&lt;br /&gt;
** test get possible team members by name in other team&lt;br /&gt;
&lt;br /&gt;
* has_user(user)&lt;br /&gt;
** test has user with valid user&lt;br /&gt;
** test has user with invalid user&lt;br /&gt;
&lt;br /&gt;
* add_member(user, assignment_id)&lt;br /&gt;
** test add member with valid user&lt;br /&gt;
** test add member already in team&lt;br /&gt;
** test add member without assignment id&lt;br /&gt;
** test add member when max team size reached&lt;br /&gt;
&lt;br /&gt;
* copy_members(new_team)&lt;br /&gt;
** test copy members to empty new team&lt;br /&gt;
** test copy members to nonempty new team&lt;br /&gt;
** test copy members with no member in current team&lt;br /&gt;
&lt;br /&gt;
* create_node_object(name, parent_id)&lt;br /&gt;
** ‘’there is a TODO on this method indicated that this is not working’’ &lt;br /&gt;
&lt;br /&gt;
* check_for_exisiting(parent, name, team_type)&lt;br /&gt;
** test check for exisiting with exisited name&lt;br /&gt;
** test check for exisiting with nonexisted name&lt;br /&gt;
&lt;br /&gt;
* delete_all_by_parent(parent)&lt;br /&gt;
** test delete with valid parents&lt;br /&gt;
** test delete with invalid parents&lt;br /&gt;
&lt;br /&gt;
* randomize_all_by_parent(parent, team_type, team_size)&lt;br /&gt;
** test randomize all by parent with exact number&lt;br /&gt;
** test randomize all by parent without enough people&lt;br /&gt;
** test randomize all by parent with remainder&lt;br /&gt;
&lt;br /&gt;
* generate_team_name(teamnameprefix)&lt;br /&gt;
** test generate prefix team name with valid name&lt;br /&gt;
** test generate prefix team name with duplicated name&lt;br /&gt;
&lt;br /&gt;
* import_team_members(starting_index, row) &lt;br /&gt;
** test import team members with valid index and row&lt;br /&gt;
** test import team members with invalid index and row&lt;br /&gt;
&lt;br /&gt;
== Possible Refacotring ==&lt;br /&gt;
=== advertise_for_team_controller.rb ===&lt;br /&gt;
* ''update'' should be ''edit'' (this is mentioned in the comments of code)&lt;br /&gt;
* ''edit'' should be reexamined since it is only retrieving the team object&lt;br /&gt;
* ''new'' is empty, so it should be removed&lt;br /&gt;
&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* There are two ''def get_participants'', the second one overwritten the first one, so the first one should be deleted.&lt;br /&gt;
&lt;br /&gt;
== Running Tests ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
To see the result of tests, run &lt;br /&gt;
 rake test TEST=test/unit/&amp;lt;filename&amp;gt; # for models&lt;br /&gt;
and &lt;br /&gt;
 rake test TEST=test/functional/&amp;lt;filename&amp;gt; # for controllers&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers from our previous work to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
The first piece of code is from student_team_controller.rb. It tests if there is already a same team name when student8 want to create a team. The second piece of code is from teams_controller_test.rb. It tests if the team number decreases when instructor1 creates a new team for a course.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, several parameters are needed. Usually we use four parameters: First, the method we are requesting. Second, an hash of request parameters for the method. Third, an optional hash of session variables. Forth, an optional hash of flash values. If we do not want to pass in the optional hash, we can set it to nil as the first piece of code shows, or we can just leave it blank as the second piece of code shows.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Qjia2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1414_st&amp;diff=84321</id>
		<title>CSC/ECE 517 Spring 2014/oss E1414 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1414_st&amp;diff=84321"/>
		<updated>2014-04-09T18:59:25Z</updated>

		<summary type="html">&lt;p&gt;Qjia2: /* app/models/teams_users.rb &amp;amp; app/controllers/teams_users_controller.rb */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
==Classes==&lt;br /&gt;
=== app/controllers/teams_controller.rb ===&lt;br /&gt;
 &lt;br /&gt;
teams_controller contains functionalities for team management for instructor/TA accounts. &lt;br /&gt;
Instructor/TA can:&lt;br /&gt;
* view current teams&lt;br /&gt;
* create new teams&lt;br /&gt;
* import/export teams&lt;br /&gt;
* delete all teams/delete specified team&lt;br /&gt;
* copy existing teams from a course down to an assignment(inherit)&lt;br /&gt;
* update team's information&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/student_team_controller.rb ===&lt;br /&gt;
The student_team_controller support team management for student account.&lt;br /&gt;
student can&lt;br /&gt;
* create team&lt;br /&gt;
* view current team (including team invitations received and sent)&lt;br /&gt;
* advertise for their team&lt;br /&gt;
* remove the advertise for their team&lt;br /&gt;
* leave the team&lt;br /&gt;
&lt;br /&gt;
=== app/models/teams_users.rb===&lt;br /&gt;
The teams_users.rb is a model belonging to both users and teams. It is used when a user is added to a team.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_users_controller.rb===&lt;br /&gt;
The teams_users_controller support team member management for instructor/TA accounts&lt;br /&gt;
Instruction/TA can:&lt;br /&gt;
* get a user name by inputting part of the name&lt;br /&gt;
* list team members of a team &lt;br /&gt;
* add a user to a team&lt;br /&gt;
* remove a team member from a team&lt;br /&gt;
* remove all members belonging to an item&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb===&lt;br /&gt;
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.&lt;br /&gt;
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
To set up our testing for the models and controllers, we need some fixtures to support. &lt;br /&gt;
Fixtures needed for corresponding classes are listed below&lt;br /&gt;
&lt;br /&gt;
=== app/models/teams_users.rb &amp;amp; app/controllers/teams_users_controller.rb ===&lt;br /&gt;
* Teams.yml&lt;br /&gt;
* Usres.yml &lt;br /&gt;
* Teams_Uers.yml&lt;br /&gt;
* Courses.yml&lt;br /&gt;
* Assignments.yml&lt;br /&gt;
&lt;br /&gt;
== Testing Scenarios ==&lt;br /&gt;
&lt;br /&gt;
=== app/models/teams_users.rb &amp;amp; app/controllers/teams_users_controller.rb ===&lt;br /&gt;
[[File:TeamUsersStory.png]]&lt;br /&gt;
&lt;br /&gt;
Based on the user story of the teams_users_controller.rb, there are also several sub-scenarios for each method in the user story.&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
== Deployment ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
To see the result of tests, run &lt;br /&gt;
 rake test TEST=test/functional/student_team_controller.rb&lt;br /&gt;
and &lt;br /&gt;
 rake test TEST=test/functional/teams_controller&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
;Total Number of Tests : 37&lt;br /&gt;
;Previous Coverage : 22.32%&lt;br /&gt;
;Current Coverage : 24.08% &lt;br /&gt;
&lt;br /&gt;
===Testing Scenarios===&lt;br /&gt;
====student_team_controller====&lt;br /&gt;
Most of the test case are straightforward. There are some of the test cases was commented out due to bug in the controller&lt;br /&gt;
* View student team (GET #view)&lt;br /&gt;
* Edit team (GET #edit)&lt;br /&gt;
* Create team with valid name (POST #create)&lt;br /&gt;
* Create team with name in use (POST #create)&lt;br /&gt;
* Update valid team name (POST #update) &lt;br /&gt;
* Update team name in use (POST #update)&lt;br /&gt;
* Update with current team name (POST #update)&lt;br /&gt;
* Advertise (GET #advertise)&lt;br /&gt;
''This is currently commented out in the committed code. It seems like the method is never called. It raises missing template error upon every call. ''&lt;br /&gt;
The &amp;lt;code&amp;gt;advertise&amp;lt;/code&amp;gt; method was previously named advertise_for_partners, but renamed due to ambiguity as there is another class with the same name. &lt;br /&gt;
&lt;br /&gt;
* Remove advertisement (GET #remove_advertisement )&lt;br /&gt;
The &amp;lt;code&amp;gt;remove_advertisement&amp;lt;/code&amp;gt; method was previously named remove, but renamed to avoid ambiguity&lt;br /&gt;
This method is never called as well, but it is functional as it do not require any template.&lt;br /&gt;
* Leave student team (GET #leave)&lt;br /&gt;
''This is currently commented out in the committed code, because it will raise error every time when called.''&lt;br /&gt;
It seems like problem happens on &lt;br /&gt;
  line 96: other_members = TeamsUser.where( ['team_id = ?', params[:team_id]]).first&lt;br /&gt;
  line 97: if other_members.length == 0&lt;br /&gt;
This will raise error due to the calling length of other_members, which is a single object but not an array.&lt;br /&gt;
Also, the related record seems to be remain undeleted in the database.&lt;br /&gt;
&lt;br /&gt;
====teams_controller====&lt;br /&gt;
Current test cases are as following.&lt;br /&gt;
* Create team should increase the number of teams by 1(GET #create)&lt;br /&gt;
* Create team should increase the number of team nodes by 1(GET #create)&lt;br /&gt;
* Create team with existing name (POST #create)&lt;br /&gt;
* Create team should redirect to list assignments (POST #create)&lt;br /&gt;
* Delete all teams (GET #delete_all)&lt;br /&gt;
* Delete all teams should redirect to list (GET #delete_all)&lt;br /&gt;
* List should receive assignment (GET #list)&lt;br /&gt;
* List should receive course (GET #list)&lt;br /&gt;
* New should assign parent (GET #new)&lt;br /&gt;
* Update team should redirect (POST #update)&lt;br /&gt;
* Update team should have validate name (POST #update)&lt;br /&gt;
* Edit team should have time (POST #edit)&lt;br /&gt;
* Delete team should redirect (POST #delete)&lt;br /&gt;
* Delete team should decrease the number of teams by 1(GET #delete)&lt;br /&gt;
* Delete team should decrease the number of team nodes by 1(GET #delete)&lt;br /&gt;
* Inherit team should redirect (POST #inherit)&lt;br /&gt;
* Bequeath team should redirect (POST #bequeath)&lt;br /&gt;
The methods in the following are ignored in testing since they are never used in current codes.&lt;br /&gt;
* create_teams_view&lt;br /&gt;
* create_teams&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
The first piece of code is from student_team_controller.rb. It tests if there is already a same team name when student8 want to create a team. The second piece of code is from teams_controller_test.rb. It tests if the team number decreases when instructor1 creates a new team for a course.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, several parameters are needed. Usually we use four parameters: First, the method we are requesting. Second, an hash of request parameters for the method. Third, an optional hash of session variables. Forth, an optional hash of flash values. If we do not want to pass in the optional hash, we can set it to nil as the first piece of code shows, or we can just leave it blank as the second piece of code shows.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not. &lt;br /&gt;
&lt;br /&gt;
==Result==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Future Works==&lt;br /&gt;
===student_team_controller===&lt;br /&gt;
''Please note that this bug was reported fixed in the newest version of master branch of expertiza, but the fix came too late''&lt;br /&gt;
&lt;br /&gt;
There are several error raised from ''leave'' method need to be fixed, as mentioned above. Future teams may need to add tests on it as soon as it fixed, since it is a crucial functionality of the student team. &lt;br /&gt;
&lt;br /&gt;
Also, methods that seems like not being used, such as &amp;lt;code&amp;gt;advertise&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;remove_advertisement&amp;lt;/code&amp;gt; may need to be double checked and see if they are redundant.&lt;br /&gt;
===teams_controller===&lt;br /&gt;
The method &amp;lt;code&amp;gt;create_teams_view&amp;lt;/code&amp;gt; does not be used at all. So it is safe to delete it.&lt;br /&gt;
&lt;br /&gt;
The method &amp;lt;code&amp;gt;create_teams&amp;lt;/code&amp;gt; calls the method &amp;lt;code&amp;gt;randomize_all_by_parent&amp;lt;/code&amp;gt;, which is not correct. The developer may want to fix these bugs. &lt;br /&gt;
&lt;br /&gt;
It's possible that we can write more testing cases if we improve the fixture.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Qjia2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1414_st&amp;diff=84320</id>
		<title>CSC/ECE 517 Spring 2014/oss E1414 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1414_st&amp;diff=84320"/>
		<updated>2014-04-09T18:57:13Z</updated>

		<summary type="html">&lt;p&gt;Qjia2: /* app/models/teams_users.rb &amp;amp; app/controllers/teams_users_controller.rb */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
==Classes==&lt;br /&gt;
=== app/controllers/teams_controller.rb ===&lt;br /&gt;
 &lt;br /&gt;
teams_controller contains functionalities for team management for instructor/TA accounts. &lt;br /&gt;
Instructor/TA can:&lt;br /&gt;
* view current teams&lt;br /&gt;
* create new teams&lt;br /&gt;
* import/export teams&lt;br /&gt;
* delete all teams/delete specified team&lt;br /&gt;
* copy existing teams from a course down to an assignment(inherit)&lt;br /&gt;
* update team's information&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/student_team_controller.rb ===&lt;br /&gt;
The student_team_controller support team management for student account.&lt;br /&gt;
student can&lt;br /&gt;
* create team&lt;br /&gt;
* view current team (including team invitations received and sent)&lt;br /&gt;
* advertise for their team&lt;br /&gt;
* remove the advertise for their team&lt;br /&gt;
* leave the team&lt;br /&gt;
&lt;br /&gt;
=== app/models/teams_users.rb===&lt;br /&gt;
The teams_users.rb is a model belonging to both users and teams. It is used when a user is added to a team.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_users_controller.rb===&lt;br /&gt;
The teams_users_controller support team member management for instructor/TA accounts&lt;br /&gt;
Instruction/TA can:&lt;br /&gt;
* get a user name by inputting part of the name&lt;br /&gt;
* list team members of a team &lt;br /&gt;
* add a user to a team&lt;br /&gt;
* remove a team member from a team&lt;br /&gt;
* remove all members belonging to an item&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb===&lt;br /&gt;
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.&lt;br /&gt;
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
To set up our testing for the models and controllers, we need some fixtures to support. &lt;br /&gt;
Fixtures needed for corresponding classes are listed below&lt;br /&gt;
&lt;br /&gt;
=== app/models/teams_users.rb &amp;amp; app/controllers/teams_users_controller.rb ===&lt;br /&gt;
* Teams.yml&lt;br /&gt;
* Usres.yml &lt;br /&gt;
* Teams_Uers.yml&lt;br /&gt;
* Courses.yml&lt;br /&gt;
* Assignments.yml&lt;br /&gt;
&lt;br /&gt;
== Testing Scenarios ==&lt;br /&gt;
&lt;br /&gt;
=== app/models/teams_users.rb &amp;amp; app/controllers/teams_users_controller.rb ===&lt;br /&gt;
[[File:TeamUsersStory.png]]&lt;br /&gt;
&lt;br /&gt;
Based on the user story of the teams_users_controller.rb, there are also several sub-scenarios for each method in the user story.&lt;br /&gt;
&lt;br /&gt;
*Auto_complete_for_user_name:&lt;br /&gt;
**Test auto_complete_for_user_name with valid user name&lt;br /&gt;
**Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
List&lt;br /&gt;
1.	Test List with valid team id&lt;br /&gt;
2.	Test List with invalid team id&lt;br /&gt;
New&lt;br /&gt;
1.	Test New with valid team id&lt;br /&gt;
2.	Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
Create&lt;br /&gt;
1.	Test Create with valid team id&lt;br /&gt;
a)	Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
b)	Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
c)	Test Create with valid user id and maximum member number is reached&lt;br /&gt;
d)	Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
2.	Test Create with invalid team id&lt;br /&gt;
a)	Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
b)	Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
c)	Test Create with valid user id and maximum member number is reached&lt;br /&gt;
d)	Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
Delete&lt;br /&gt;
1.	Test Delete with valid user id&lt;br /&gt;
2.	Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
Delete_select&lt;br /&gt;
1.	Test Delete_select with valid item id&lt;br /&gt;
2.	Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
== Deployment ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
To see the result of tests, run &lt;br /&gt;
 rake test TEST=test/functional/student_team_controller.rb&lt;br /&gt;
and &lt;br /&gt;
 rake test TEST=test/functional/teams_controller&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
;Total Number of Tests : 37&lt;br /&gt;
;Previous Coverage : 22.32%&lt;br /&gt;
;Current Coverage : 24.08% &lt;br /&gt;
&lt;br /&gt;
===Testing Scenarios===&lt;br /&gt;
====student_team_controller====&lt;br /&gt;
Most of the test case are straightforward. There are some of the test cases was commented out due to bug in the controller&lt;br /&gt;
* View student team (GET #view)&lt;br /&gt;
* Edit team (GET #edit)&lt;br /&gt;
* Create team with valid name (POST #create)&lt;br /&gt;
* Create team with name in use (POST #create)&lt;br /&gt;
* Update valid team name (POST #update) &lt;br /&gt;
* Update team name in use (POST #update)&lt;br /&gt;
* Update with current team name (POST #update)&lt;br /&gt;
* Advertise (GET #advertise)&lt;br /&gt;
''This is currently commented out in the committed code. It seems like the method is never called. It raises missing template error upon every call. ''&lt;br /&gt;
The &amp;lt;code&amp;gt;advertise&amp;lt;/code&amp;gt; method was previously named advertise_for_partners, but renamed due to ambiguity as there is another class with the same name. &lt;br /&gt;
&lt;br /&gt;
* Remove advertisement (GET #remove_advertisement )&lt;br /&gt;
The &amp;lt;code&amp;gt;remove_advertisement&amp;lt;/code&amp;gt; method was previously named remove, but renamed to avoid ambiguity&lt;br /&gt;
This method is never called as well, but it is functional as it do not require any template.&lt;br /&gt;
* Leave student team (GET #leave)&lt;br /&gt;
''This is currently commented out in the committed code, because it will raise error every time when called.''&lt;br /&gt;
It seems like problem happens on &lt;br /&gt;
  line 96: other_members = TeamsUser.where( ['team_id = ?', params[:team_id]]).first&lt;br /&gt;
  line 97: if other_members.length == 0&lt;br /&gt;
This will raise error due to the calling length of other_members, which is a single object but not an array.&lt;br /&gt;
Also, the related record seems to be remain undeleted in the database.&lt;br /&gt;
&lt;br /&gt;
====teams_controller====&lt;br /&gt;
Current test cases are as following.&lt;br /&gt;
* Create team should increase the number of teams by 1(GET #create)&lt;br /&gt;
* Create team should increase the number of team nodes by 1(GET #create)&lt;br /&gt;
* Create team with existing name (POST #create)&lt;br /&gt;
* Create team should redirect to list assignments (POST #create)&lt;br /&gt;
* Delete all teams (GET #delete_all)&lt;br /&gt;
* Delete all teams should redirect to list (GET #delete_all)&lt;br /&gt;
* List should receive assignment (GET #list)&lt;br /&gt;
* List should receive course (GET #list)&lt;br /&gt;
* New should assign parent (GET #new)&lt;br /&gt;
* Update team should redirect (POST #update)&lt;br /&gt;
* Update team should have validate name (POST #update)&lt;br /&gt;
* Edit team should have time (POST #edit)&lt;br /&gt;
* Delete team should redirect (POST #delete)&lt;br /&gt;
* Delete team should decrease the number of teams by 1(GET #delete)&lt;br /&gt;
* Delete team should decrease the number of team nodes by 1(GET #delete)&lt;br /&gt;
* Inherit team should redirect (POST #inherit)&lt;br /&gt;
* Bequeath team should redirect (POST #bequeath)&lt;br /&gt;
The methods in the following are ignored in testing since they are never used in current codes.&lt;br /&gt;
* create_teams_view&lt;br /&gt;
* create_teams&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
The first piece of code is from student_team_controller.rb. It tests if there is already a same team name when student8 want to create a team. The second piece of code is from teams_controller_test.rb. It tests if the team number decreases when instructor1 creates a new team for a course.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, several parameters are needed. Usually we use four parameters: First, the method we are requesting. Second, an hash of request parameters for the method. Third, an optional hash of session variables. Forth, an optional hash of flash values. If we do not want to pass in the optional hash, we can set it to nil as the first piece of code shows, or we can just leave it blank as the second piece of code shows.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not. &lt;br /&gt;
&lt;br /&gt;
==Result==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Future Works==&lt;br /&gt;
===student_team_controller===&lt;br /&gt;
''Please note that this bug was reported fixed in the newest version of master branch of expertiza, but the fix came too late''&lt;br /&gt;
&lt;br /&gt;
There are several error raised from ''leave'' method need to be fixed, as mentioned above. Future teams may need to add tests on it as soon as it fixed, since it is a crucial functionality of the student team. &lt;br /&gt;
&lt;br /&gt;
Also, methods that seems like not being used, such as &amp;lt;code&amp;gt;advertise&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;remove_advertisement&amp;lt;/code&amp;gt; may need to be double checked and see if they are redundant.&lt;br /&gt;
===teams_controller===&lt;br /&gt;
The method &amp;lt;code&amp;gt;create_teams_view&amp;lt;/code&amp;gt; does not be used at all. So it is safe to delete it.&lt;br /&gt;
&lt;br /&gt;
The method &amp;lt;code&amp;gt;create_teams&amp;lt;/code&amp;gt; calls the method &amp;lt;code&amp;gt;randomize_all_by_parent&amp;lt;/code&amp;gt;, which is not correct. The developer may want to fix these bugs. &lt;br /&gt;
&lt;br /&gt;
It's possible that we can write more testing cases if we improve the fixture.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Qjia2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1414_st&amp;diff=84319</id>
		<title>CSC/ECE 517 Spring 2014/oss E1414 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1414_st&amp;diff=84319"/>
		<updated>2014-04-09T18:56:02Z</updated>

		<summary type="html">&lt;p&gt;Qjia2: /* app/models/teams_users.rb &amp;amp; app/controllers/teams_users_controller.rb */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
==Classes==&lt;br /&gt;
=== app/controllers/teams_controller.rb ===&lt;br /&gt;
 &lt;br /&gt;
teams_controller contains functionalities for team management for instructor/TA accounts. &lt;br /&gt;
Instructor/TA can:&lt;br /&gt;
* view current teams&lt;br /&gt;
* create new teams&lt;br /&gt;
* import/export teams&lt;br /&gt;
* delete all teams/delete specified team&lt;br /&gt;
* copy existing teams from a course down to an assignment(inherit)&lt;br /&gt;
* update team's information&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/student_team_controller.rb ===&lt;br /&gt;
The student_team_controller support team management for student account.&lt;br /&gt;
student can&lt;br /&gt;
* create team&lt;br /&gt;
* view current team (including team invitations received and sent)&lt;br /&gt;
* advertise for their team&lt;br /&gt;
* remove the advertise for their team&lt;br /&gt;
* leave the team&lt;br /&gt;
&lt;br /&gt;
=== app/models/teams_users.rb===&lt;br /&gt;
The teams_users.rb is a model belonging to both users and teams. It is used when a user is added to a team.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_users_controller.rb===&lt;br /&gt;
The teams_users_controller support team member management for instructor/TA accounts&lt;br /&gt;
Instruction/TA can:&lt;br /&gt;
* get a user name by inputting part of the name&lt;br /&gt;
* list team members of a team &lt;br /&gt;
* add a user to a team&lt;br /&gt;
* remove a team member from a team&lt;br /&gt;
* remove all members belonging to an item&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb===&lt;br /&gt;
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.&lt;br /&gt;
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
To set up our testing for the models and controllers, we need some fixtures to support. &lt;br /&gt;
Fixtures needed for corresponding classes are listed below&lt;br /&gt;
&lt;br /&gt;
=== app/models/teams_users.rb &amp;amp; app/controllers/teams_users_controller.rb ===&lt;br /&gt;
* Teams.yml&lt;br /&gt;
* Usres.yml &lt;br /&gt;
* Teams_Uers.yml&lt;br /&gt;
* Courses.yml&lt;br /&gt;
* Assignments.yml&lt;br /&gt;
&lt;br /&gt;
== Testing Scenarios ==&lt;br /&gt;
&lt;br /&gt;
=== app/models/teams_users.rb &amp;amp; app/controllers/teams_users_controller.rb ===&lt;br /&gt;
[[File:TeamUsersStory.png]]&lt;br /&gt;
&lt;br /&gt;
== Deployment ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
To see the result of tests, run &lt;br /&gt;
 rake test TEST=test/functional/student_team_controller.rb&lt;br /&gt;
and &lt;br /&gt;
 rake test TEST=test/functional/teams_controller&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
;Total Number of Tests : 37&lt;br /&gt;
;Previous Coverage : 22.32%&lt;br /&gt;
;Current Coverage : 24.08% &lt;br /&gt;
&lt;br /&gt;
===Testing Scenarios===&lt;br /&gt;
====student_team_controller====&lt;br /&gt;
Most of the test case are straightforward. There are some of the test cases was commented out due to bug in the controller&lt;br /&gt;
* View student team (GET #view)&lt;br /&gt;
* Edit team (GET #edit)&lt;br /&gt;
* Create team with valid name (POST #create)&lt;br /&gt;
* Create team with name in use (POST #create)&lt;br /&gt;
* Update valid team name (POST #update) &lt;br /&gt;
* Update team name in use (POST #update)&lt;br /&gt;
* Update with current team name (POST #update)&lt;br /&gt;
* Advertise (GET #advertise)&lt;br /&gt;
''This is currently commented out in the committed code. It seems like the method is never called. It raises missing template error upon every call. ''&lt;br /&gt;
The &amp;lt;code&amp;gt;advertise&amp;lt;/code&amp;gt; method was previously named advertise_for_partners, but renamed due to ambiguity as there is another class with the same name. &lt;br /&gt;
&lt;br /&gt;
* Remove advertisement (GET #remove_advertisement )&lt;br /&gt;
The &amp;lt;code&amp;gt;remove_advertisement&amp;lt;/code&amp;gt; method was previously named remove, but renamed to avoid ambiguity&lt;br /&gt;
This method is never called as well, but it is functional as it do not require any template.&lt;br /&gt;
* Leave student team (GET #leave)&lt;br /&gt;
''This is currently commented out in the committed code, because it will raise error every time when called.''&lt;br /&gt;
It seems like problem happens on &lt;br /&gt;
  line 96: other_members = TeamsUser.where( ['team_id = ?', params[:team_id]]).first&lt;br /&gt;
  line 97: if other_members.length == 0&lt;br /&gt;
This will raise error due to the calling length of other_members, which is a single object but not an array.&lt;br /&gt;
Also, the related record seems to be remain undeleted in the database.&lt;br /&gt;
&lt;br /&gt;
====teams_controller====&lt;br /&gt;
Current test cases are as following.&lt;br /&gt;
* Create team should increase the number of teams by 1(GET #create)&lt;br /&gt;
* Create team should increase the number of team nodes by 1(GET #create)&lt;br /&gt;
* Create team with existing name (POST #create)&lt;br /&gt;
* Create team should redirect to list assignments (POST #create)&lt;br /&gt;
* Delete all teams (GET #delete_all)&lt;br /&gt;
* Delete all teams should redirect to list (GET #delete_all)&lt;br /&gt;
* List should receive assignment (GET #list)&lt;br /&gt;
* List should receive course (GET #list)&lt;br /&gt;
* New should assign parent (GET #new)&lt;br /&gt;
* Update team should redirect (POST #update)&lt;br /&gt;
* Update team should have validate name (POST #update)&lt;br /&gt;
* Edit team should have time (POST #edit)&lt;br /&gt;
* Delete team should redirect (POST #delete)&lt;br /&gt;
* Delete team should decrease the number of teams by 1(GET #delete)&lt;br /&gt;
* Delete team should decrease the number of team nodes by 1(GET #delete)&lt;br /&gt;
* Inherit team should redirect (POST #inherit)&lt;br /&gt;
* Bequeath team should redirect (POST #bequeath)&lt;br /&gt;
The methods in the following are ignored in testing since they are never used in current codes.&lt;br /&gt;
* create_teams_view&lt;br /&gt;
* create_teams&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
The first piece of code is from student_team_controller.rb. It tests if there is already a same team name when student8 want to create a team. The second piece of code is from teams_controller_test.rb. It tests if the team number decreases when instructor1 creates a new team for a course.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, several parameters are needed. Usually we use four parameters: First, the method we are requesting. Second, an hash of request parameters for the method. Third, an optional hash of session variables. Forth, an optional hash of flash values. If we do not want to pass in the optional hash, we can set it to nil as the first piece of code shows, or we can just leave it blank as the second piece of code shows.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not. &lt;br /&gt;
&lt;br /&gt;
==Result==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Future Works==&lt;br /&gt;
===student_team_controller===&lt;br /&gt;
''Please note that this bug was reported fixed in the newest version of master branch of expertiza, but the fix came too late''&lt;br /&gt;
&lt;br /&gt;
There are several error raised from ''leave'' method need to be fixed, as mentioned above. Future teams may need to add tests on it as soon as it fixed, since it is a crucial functionality of the student team. &lt;br /&gt;
&lt;br /&gt;
Also, methods that seems like not being used, such as &amp;lt;code&amp;gt;advertise&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;remove_advertisement&amp;lt;/code&amp;gt; may need to be double checked and see if they are redundant.&lt;br /&gt;
===teams_controller===&lt;br /&gt;
The method &amp;lt;code&amp;gt;create_teams_view&amp;lt;/code&amp;gt; does not be used at all. So it is safe to delete it.&lt;br /&gt;
&lt;br /&gt;
The method &amp;lt;code&amp;gt;create_teams&amp;lt;/code&amp;gt; calls the method &amp;lt;code&amp;gt;randomize_all_by_parent&amp;lt;/code&amp;gt;, which is not correct. The developer may want to fix these bugs. &lt;br /&gt;
&lt;br /&gt;
It's possible that we can write more testing cases if we improve the fixture.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Qjia2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1414_st&amp;diff=84318</id>
		<title>CSC/ECE 517 Spring 2014/oss E1414 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1414_st&amp;diff=84318"/>
		<updated>2014-04-09T18:55:40Z</updated>

		<summary type="html">&lt;p&gt;Qjia2: /* app/models/teams_users.rb &amp;amp; app/controllers/teams_users_controller.rb */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
==Classes==&lt;br /&gt;
=== app/controllers/teams_controller.rb ===&lt;br /&gt;
 &lt;br /&gt;
teams_controller contains functionalities for team management for instructor/TA accounts. &lt;br /&gt;
Instructor/TA can:&lt;br /&gt;
* view current teams&lt;br /&gt;
* create new teams&lt;br /&gt;
* import/export teams&lt;br /&gt;
* delete all teams/delete specified team&lt;br /&gt;
* copy existing teams from a course down to an assignment(inherit)&lt;br /&gt;
* update team's information&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/student_team_controller.rb ===&lt;br /&gt;
The student_team_controller support team management for student account.&lt;br /&gt;
student can&lt;br /&gt;
* create team&lt;br /&gt;
* view current team (including team invitations received and sent)&lt;br /&gt;
* advertise for their team&lt;br /&gt;
* remove the advertise for their team&lt;br /&gt;
* leave the team&lt;br /&gt;
&lt;br /&gt;
=== app/models/teams_users.rb===&lt;br /&gt;
The teams_users.rb is a model belonging to both users and teams. It is used when a user is added to a team.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_users_controller.rb===&lt;br /&gt;
The teams_users_controller support team member management for instructor/TA accounts&lt;br /&gt;
Instruction/TA can:&lt;br /&gt;
* get a user name by inputting part of the name&lt;br /&gt;
* list team members of a team &lt;br /&gt;
* add a user to a team&lt;br /&gt;
* remove a team member from a team&lt;br /&gt;
* remove all members belonging to an item&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb===&lt;br /&gt;
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.&lt;br /&gt;
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
To set up our testing for the models and controllers, we need some fixtures to support. &lt;br /&gt;
Fixtures needed for corresponding classes are listed below&lt;br /&gt;
&lt;br /&gt;
=== app/models/teams_users.rb &amp;amp; app/controllers/teams_users_controller.rb ===&lt;br /&gt;
* Teams.yml&lt;br /&gt;
* Usres.yml &lt;br /&gt;
* Teams_Uers.yml&lt;br /&gt;
* Courses.yml&lt;br /&gt;
* Assignments.yml&lt;br /&gt;
&lt;br /&gt;
== Testing Scenarios ==&lt;br /&gt;
&lt;br /&gt;
=== app/models/teams_users.rb &amp;amp; app/controllers/teams_users_controller.rb ===&lt;br /&gt;
[[File:TeamUserStory.png]]&lt;br /&gt;
&lt;br /&gt;
== Deployment ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
To see the result of tests, run &lt;br /&gt;
 rake test TEST=test/functional/student_team_controller.rb&lt;br /&gt;
and &lt;br /&gt;
 rake test TEST=test/functional/teams_controller&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
;Total Number of Tests : 37&lt;br /&gt;
;Previous Coverage : 22.32%&lt;br /&gt;
;Current Coverage : 24.08% &lt;br /&gt;
&lt;br /&gt;
===Testing Scenarios===&lt;br /&gt;
====student_team_controller====&lt;br /&gt;
Most of the test case are straightforward. There are some of the test cases was commented out due to bug in the controller&lt;br /&gt;
* View student team (GET #view)&lt;br /&gt;
* Edit team (GET #edit)&lt;br /&gt;
* Create team with valid name (POST #create)&lt;br /&gt;
* Create team with name in use (POST #create)&lt;br /&gt;
* Update valid team name (POST #update) &lt;br /&gt;
* Update team name in use (POST #update)&lt;br /&gt;
* Update with current team name (POST #update)&lt;br /&gt;
* Advertise (GET #advertise)&lt;br /&gt;
''This is currently commented out in the committed code. It seems like the method is never called. It raises missing template error upon every call. ''&lt;br /&gt;
The &amp;lt;code&amp;gt;advertise&amp;lt;/code&amp;gt; method was previously named advertise_for_partners, but renamed due to ambiguity as there is another class with the same name. &lt;br /&gt;
&lt;br /&gt;
* Remove advertisement (GET #remove_advertisement )&lt;br /&gt;
The &amp;lt;code&amp;gt;remove_advertisement&amp;lt;/code&amp;gt; method was previously named remove, but renamed to avoid ambiguity&lt;br /&gt;
This method is never called as well, but it is functional as it do not require any template.&lt;br /&gt;
* Leave student team (GET #leave)&lt;br /&gt;
''This is currently commented out in the committed code, because it will raise error every time when called.''&lt;br /&gt;
It seems like problem happens on &lt;br /&gt;
  line 96: other_members = TeamsUser.where( ['team_id = ?', params[:team_id]]).first&lt;br /&gt;
  line 97: if other_members.length == 0&lt;br /&gt;
This will raise error due to the calling length of other_members, which is a single object but not an array.&lt;br /&gt;
Also, the related record seems to be remain undeleted in the database.&lt;br /&gt;
&lt;br /&gt;
====teams_controller====&lt;br /&gt;
Current test cases are as following.&lt;br /&gt;
* Create team should increase the number of teams by 1(GET #create)&lt;br /&gt;
* Create team should increase the number of team nodes by 1(GET #create)&lt;br /&gt;
* Create team with existing name (POST #create)&lt;br /&gt;
* Create team should redirect to list assignments (POST #create)&lt;br /&gt;
* Delete all teams (GET #delete_all)&lt;br /&gt;
* Delete all teams should redirect to list (GET #delete_all)&lt;br /&gt;
* List should receive assignment (GET #list)&lt;br /&gt;
* List should receive course (GET #list)&lt;br /&gt;
* New should assign parent (GET #new)&lt;br /&gt;
* Update team should redirect (POST #update)&lt;br /&gt;
* Update team should have validate name (POST #update)&lt;br /&gt;
* Edit team should have time (POST #edit)&lt;br /&gt;
* Delete team should redirect (POST #delete)&lt;br /&gt;
* Delete team should decrease the number of teams by 1(GET #delete)&lt;br /&gt;
* Delete team should decrease the number of team nodes by 1(GET #delete)&lt;br /&gt;
* Inherit team should redirect (POST #inherit)&lt;br /&gt;
* Bequeath team should redirect (POST #bequeath)&lt;br /&gt;
The methods in the following are ignored in testing since they are never used in current codes.&lt;br /&gt;
* create_teams_view&lt;br /&gt;
* create_teams&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
The first piece of code is from student_team_controller.rb. It tests if there is already a same team name when student8 want to create a team. The second piece of code is from teams_controller_test.rb. It tests if the team number decreases when instructor1 creates a new team for a course.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, several parameters are needed. Usually we use four parameters: First, the method we are requesting. Second, an hash of request parameters for the method. Third, an optional hash of session variables. Forth, an optional hash of flash values. If we do not want to pass in the optional hash, we can set it to nil as the first piece of code shows, or we can just leave it blank as the second piece of code shows.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not. &lt;br /&gt;
&lt;br /&gt;
==Result==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Future Works==&lt;br /&gt;
===student_team_controller===&lt;br /&gt;
''Please note that this bug was reported fixed in the newest version of master branch of expertiza, but the fix came too late''&lt;br /&gt;
&lt;br /&gt;
There are several error raised from ''leave'' method need to be fixed, as mentioned above. Future teams may need to add tests on it as soon as it fixed, since it is a crucial functionality of the student team. &lt;br /&gt;
&lt;br /&gt;
Also, methods that seems like not being used, such as &amp;lt;code&amp;gt;advertise&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;remove_advertisement&amp;lt;/code&amp;gt; may need to be double checked and see if they are redundant.&lt;br /&gt;
===teams_controller===&lt;br /&gt;
The method &amp;lt;code&amp;gt;create_teams_view&amp;lt;/code&amp;gt; does not be used at all. So it is safe to delete it.&lt;br /&gt;
&lt;br /&gt;
The method &amp;lt;code&amp;gt;create_teams&amp;lt;/code&amp;gt; calls the method &amp;lt;code&amp;gt;randomize_all_by_parent&amp;lt;/code&amp;gt;, which is not correct. The developer may want to fix these bugs. &lt;br /&gt;
&lt;br /&gt;
It's possible that we can write more testing cases if we improve the fixture.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Qjia2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1414_st&amp;diff=84317</id>
		<title>CSC/ECE 517 Spring 2014/oss E1414 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1414_st&amp;diff=84317"/>
		<updated>2014-04-09T18:55:10Z</updated>

		<summary type="html">&lt;p&gt;Qjia2: /* app/models/teams_users.rb &amp;amp; app/controllers/teams_users_controller.rb */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
==Classes==&lt;br /&gt;
=== app/controllers/teams_controller.rb ===&lt;br /&gt;
 &lt;br /&gt;
teams_controller contains functionalities for team management for instructor/TA accounts. &lt;br /&gt;
Instructor/TA can:&lt;br /&gt;
* view current teams&lt;br /&gt;
* create new teams&lt;br /&gt;
* import/export teams&lt;br /&gt;
* delete all teams/delete specified team&lt;br /&gt;
* copy existing teams from a course down to an assignment(inherit)&lt;br /&gt;
* update team's information&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/student_team_controller.rb ===&lt;br /&gt;
The student_team_controller support team management for student account.&lt;br /&gt;
student can&lt;br /&gt;
* create team&lt;br /&gt;
* view current team (including team invitations received and sent)&lt;br /&gt;
* advertise for their team&lt;br /&gt;
* remove the advertise for their team&lt;br /&gt;
* leave the team&lt;br /&gt;
&lt;br /&gt;
=== app/models/teams_users.rb===&lt;br /&gt;
The teams_users.rb is a model belonging to both users and teams. It is used when a user is added to a team.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_users_controller.rb===&lt;br /&gt;
The teams_users_controller support team member management for instructor/TA accounts&lt;br /&gt;
Instruction/TA can:&lt;br /&gt;
* get a user name by inputting part of the name&lt;br /&gt;
* list team members of a team &lt;br /&gt;
* add a user to a team&lt;br /&gt;
* remove a team member from a team&lt;br /&gt;
* remove all members belonging to an item&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb===&lt;br /&gt;
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.&lt;br /&gt;
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
To set up our testing for the models and controllers, we need some fixtures to support. &lt;br /&gt;
Fixtures needed for corresponding classes are listed below&lt;br /&gt;
&lt;br /&gt;
=== app/models/teams_users.rb &amp;amp; app/controllers/teams_users_controller.rb ===&lt;br /&gt;
* Teams.yml&lt;br /&gt;
* Usres.yml &lt;br /&gt;
* Teams_Uers.yml&lt;br /&gt;
* Courses.yml&lt;br /&gt;
* Assignments.yml&lt;br /&gt;
&lt;br /&gt;
== Testing Scenarios ==&lt;br /&gt;
&lt;br /&gt;
=== app/models/teams_users.rb &amp;amp; app/controllers/teams_users_controller.rb ===&lt;br /&gt;
[[File:teamsUserStory.png]]&lt;br /&gt;
&lt;br /&gt;
== Deployment ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
To see the result of tests, run &lt;br /&gt;
 rake test TEST=test/functional/student_team_controller.rb&lt;br /&gt;
and &lt;br /&gt;
 rake test TEST=test/functional/teams_controller&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
;Total Number of Tests : 37&lt;br /&gt;
;Previous Coverage : 22.32%&lt;br /&gt;
;Current Coverage : 24.08% &lt;br /&gt;
&lt;br /&gt;
===Testing Scenarios===&lt;br /&gt;
====student_team_controller====&lt;br /&gt;
Most of the test case are straightforward. There are some of the test cases was commented out due to bug in the controller&lt;br /&gt;
* View student team (GET #view)&lt;br /&gt;
* Edit team (GET #edit)&lt;br /&gt;
* Create team with valid name (POST #create)&lt;br /&gt;
* Create team with name in use (POST #create)&lt;br /&gt;
* Update valid team name (POST #update) &lt;br /&gt;
* Update team name in use (POST #update)&lt;br /&gt;
* Update with current team name (POST #update)&lt;br /&gt;
* Advertise (GET #advertise)&lt;br /&gt;
''This is currently commented out in the committed code. It seems like the method is never called. It raises missing template error upon every call. ''&lt;br /&gt;
The &amp;lt;code&amp;gt;advertise&amp;lt;/code&amp;gt; method was previously named advertise_for_partners, but renamed due to ambiguity as there is another class with the same name. &lt;br /&gt;
&lt;br /&gt;
* Remove advertisement (GET #remove_advertisement )&lt;br /&gt;
The &amp;lt;code&amp;gt;remove_advertisement&amp;lt;/code&amp;gt; method was previously named remove, but renamed to avoid ambiguity&lt;br /&gt;
This method is never called as well, but it is functional as it do not require any template.&lt;br /&gt;
* Leave student team (GET #leave)&lt;br /&gt;
''This is currently commented out in the committed code, because it will raise error every time when called.''&lt;br /&gt;
It seems like problem happens on &lt;br /&gt;
  line 96: other_members = TeamsUser.where( ['team_id = ?', params[:team_id]]).first&lt;br /&gt;
  line 97: if other_members.length == 0&lt;br /&gt;
This will raise error due to the calling length of other_members, which is a single object but not an array.&lt;br /&gt;
Also, the related record seems to be remain undeleted in the database.&lt;br /&gt;
&lt;br /&gt;
====teams_controller====&lt;br /&gt;
Current test cases are as following.&lt;br /&gt;
* Create team should increase the number of teams by 1(GET #create)&lt;br /&gt;
* Create team should increase the number of team nodes by 1(GET #create)&lt;br /&gt;
* Create team with existing name (POST #create)&lt;br /&gt;
* Create team should redirect to list assignments (POST #create)&lt;br /&gt;
* Delete all teams (GET #delete_all)&lt;br /&gt;
* Delete all teams should redirect to list (GET #delete_all)&lt;br /&gt;
* List should receive assignment (GET #list)&lt;br /&gt;
* List should receive course (GET #list)&lt;br /&gt;
* New should assign parent (GET #new)&lt;br /&gt;
* Update team should redirect (POST #update)&lt;br /&gt;
* Update team should have validate name (POST #update)&lt;br /&gt;
* Edit team should have time (POST #edit)&lt;br /&gt;
* Delete team should redirect (POST #delete)&lt;br /&gt;
* Delete team should decrease the number of teams by 1(GET #delete)&lt;br /&gt;
* Delete team should decrease the number of team nodes by 1(GET #delete)&lt;br /&gt;
* Inherit team should redirect (POST #inherit)&lt;br /&gt;
* Bequeath team should redirect (POST #bequeath)&lt;br /&gt;
The methods in the following are ignored in testing since they are never used in current codes.&lt;br /&gt;
* create_teams_view&lt;br /&gt;
* create_teams&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
The first piece of code is from student_team_controller.rb. It tests if there is already a same team name when student8 want to create a team. The second piece of code is from teams_controller_test.rb. It tests if the team number decreases when instructor1 creates a new team for a course.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, several parameters are needed. Usually we use four parameters: First, the method we are requesting. Second, an hash of request parameters for the method. Third, an optional hash of session variables. Forth, an optional hash of flash values. If we do not want to pass in the optional hash, we can set it to nil as the first piece of code shows, or we can just leave it blank as the second piece of code shows.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not. &lt;br /&gt;
&lt;br /&gt;
==Result==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Future Works==&lt;br /&gt;
===student_team_controller===&lt;br /&gt;
''Please note that this bug was reported fixed in the newest version of master branch of expertiza, but the fix came too late''&lt;br /&gt;
&lt;br /&gt;
There are several error raised from ''leave'' method need to be fixed, as mentioned above. Future teams may need to add tests on it as soon as it fixed, since it is a crucial functionality of the student team. &lt;br /&gt;
&lt;br /&gt;
Also, methods that seems like not being used, such as &amp;lt;code&amp;gt;advertise&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;remove_advertisement&amp;lt;/code&amp;gt; may need to be double checked and see if they are redundant.&lt;br /&gt;
===teams_controller===&lt;br /&gt;
The method &amp;lt;code&amp;gt;create_teams_view&amp;lt;/code&amp;gt; does not be used at all. So it is safe to delete it.&lt;br /&gt;
&lt;br /&gt;
The method &amp;lt;code&amp;gt;create_teams&amp;lt;/code&amp;gt; calls the method &amp;lt;code&amp;gt;randomize_all_by_parent&amp;lt;/code&amp;gt;, which is not correct. The developer may want to fix these bugs. &lt;br /&gt;
&lt;br /&gt;
It's possible that we can write more testing cases if we improve the fixture.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Qjia2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:TeamUsersStory.png&amp;diff=84316</id>
		<title>File:TeamUsersStory.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:TeamUsersStory.png&amp;diff=84316"/>
		<updated>2014-04-09T18:54:31Z</updated>

		<summary type="html">&lt;p&gt;Qjia2: user story&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;user story&lt;/div&gt;</summary>
		<author><name>Qjia2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:QQ%E6%88%AA%E5%9B%BE20140409144837.png&amp;diff=84315</id>
		<title>File:QQ截图20140409144837.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:QQ%E6%88%AA%E5%9B%BE20140409144837.png&amp;diff=84315"/>
		<updated>2014-04-09T18:52:35Z</updated>

		<summary type="html">&lt;p&gt;Qjia2: Blanked the page&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Qjia2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1414_st&amp;diff=84314</id>
		<title>CSC/ECE 517 Spring 2014/oss E1414 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1414_st&amp;diff=84314"/>
		<updated>2014-04-09T18:50:03Z</updated>

		<summary type="html">&lt;p&gt;Qjia2: /* Tasks */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
==Classes==&lt;br /&gt;
=== app/controllers/teams_controller.rb ===&lt;br /&gt;
 &lt;br /&gt;
teams_controller contains functionalities for team management for instructor/TA accounts. &lt;br /&gt;
Instructor/TA can:&lt;br /&gt;
* view current teams&lt;br /&gt;
* create new teams&lt;br /&gt;
* import/export teams&lt;br /&gt;
* delete all teams/delete specified team&lt;br /&gt;
* copy existing teams from a course down to an assignment(inherit)&lt;br /&gt;
* update team's information&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/student_team_controller.rb ===&lt;br /&gt;
The student_team_controller support team management for student account.&lt;br /&gt;
student can&lt;br /&gt;
* create team&lt;br /&gt;
* view current team (including team invitations received and sent)&lt;br /&gt;
* advertise for their team&lt;br /&gt;
* remove the advertise for their team&lt;br /&gt;
* leave the team&lt;br /&gt;
&lt;br /&gt;
=== app/models/teams_users.rb===&lt;br /&gt;
The teams_users.rb is a model belonging to both users and teams. It is used when a user is added to a team.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_users_controller.rb===&lt;br /&gt;
The teams_users_controller support team member management for instructor/TA accounts&lt;br /&gt;
Instruction/TA can:&lt;br /&gt;
* get a user name by inputting part of the name&lt;br /&gt;
* list team members of a team &lt;br /&gt;
* add a user to a team&lt;br /&gt;
* remove a team member from a team&lt;br /&gt;
* remove all members belonging to an item&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb===&lt;br /&gt;
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.&lt;br /&gt;
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
To set up our testing for the models and controllers, we need some fixtures to support. &lt;br /&gt;
Fixtures needed for corresponding classes are listed below&lt;br /&gt;
&lt;br /&gt;
=== app/models/teams_users.rb &amp;amp; app/controllers/teams_users_controller.rb ===&lt;br /&gt;
* Teams.yml&lt;br /&gt;
* Usres.yml &lt;br /&gt;
* Teams_Uers.yml&lt;br /&gt;
* Courses.yml&lt;br /&gt;
* Assignments.yml&lt;br /&gt;
&lt;br /&gt;
== Testing Scenarios ==&lt;br /&gt;
&lt;br /&gt;
=== app/models/teams_users.rb &amp;amp; app/controllers/teams_users_controller.rb ===&lt;br /&gt;
&lt;br /&gt;
== Deployment ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
To see the result of tests, run &lt;br /&gt;
 rake test TEST=test/functional/student_team_controller.rb&lt;br /&gt;
and &lt;br /&gt;
 rake test TEST=test/functional/teams_controller&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
;Total Number of Tests : 37&lt;br /&gt;
;Previous Coverage : 22.32%&lt;br /&gt;
;Current Coverage : 24.08% &lt;br /&gt;
&lt;br /&gt;
===Testing Scenarios===&lt;br /&gt;
====student_team_controller====&lt;br /&gt;
Most of the test case are straightforward. There are some of the test cases was commented out due to bug in the controller&lt;br /&gt;
* View student team (GET #view)&lt;br /&gt;
* Edit team (GET #edit)&lt;br /&gt;
* Create team with valid name (POST #create)&lt;br /&gt;
* Create team with name in use (POST #create)&lt;br /&gt;
* Update valid team name (POST #update) &lt;br /&gt;
* Update team name in use (POST #update)&lt;br /&gt;
* Update with current team name (POST #update)&lt;br /&gt;
* Advertise (GET #advertise)&lt;br /&gt;
''This is currently commented out in the committed code. It seems like the method is never called. It raises missing template error upon every call. ''&lt;br /&gt;
The &amp;lt;code&amp;gt;advertise&amp;lt;/code&amp;gt; method was previously named advertise_for_partners, but renamed due to ambiguity as there is another class with the same name. &lt;br /&gt;
&lt;br /&gt;
* Remove advertisement (GET #remove_advertisement )&lt;br /&gt;
The &amp;lt;code&amp;gt;remove_advertisement&amp;lt;/code&amp;gt; method was previously named remove, but renamed to avoid ambiguity&lt;br /&gt;
This method is never called as well, but it is functional as it do not require any template.&lt;br /&gt;
* Leave student team (GET #leave)&lt;br /&gt;
''This is currently commented out in the committed code, because it will raise error every time when called.''&lt;br /&gt;
It seems like problem happens on &lt;br /&gt;
  line 96: other_members = TeamsUser.where( ['team_id = ?', params[:team_id]]).first&lt;br /&gt;
  line 97: if other_members.length == 0&lt;br /&gt;
This will raise error due to the calling length of other_members, which is a single object but not an array.&lt;br /&gt;
Also, the related record seems to be remain undeleted in the database.&lt;br /&gt;
&lt;br /&gt;
====teams_controller====&lt;br /&gt;
Current test cases are as following.&lt;br /&gt;
* Create team should increase the number of teams by 1(GET #create)&lt;br /&gt;
* Create team should increase the number of team nodes by 1(GET #create)&lt;br /&gt;
* Create team with existing name (POST #create)&lt;br /&gt;
* Create team should redirect to list assignments (POST #create)&lt;br /&gt;
* Delete all teams (GET #delete_all)&lt;br /&gt;
* Delete all teams should redirect to list (GET #delete_all)&lt;br /&gt;
* List should receive assignment (GET #list)&lt;br /&gt;
* List should receive course (GET #list)&lt;br /&gt;
* New should assign parent (GET #new)&lt;br /&gt;
* Update team should redirect (POST #update)&lt;br /&gt;
* Update team should have validate name (POST #update)&lt;br /&gt;
* Edit team should have time (POST #edit)&lt;br /&gt;
* Delete team should redirect (POST #delete)&lt;br /&gt;
* Delete team should decrease the number of teams by 1(GET #delete)&lt;br /&gt;
* Delete team should decrease the number of team nodes by 1(GET #delete)&lt;br /&gt;
* Inherit team should redirect (POST #inherit)&lt;br /&gt;
* Bequeath team should redirect (POST #bequeath)&lt;br /&gt;
The methods in the following are ignored in testing since they are never used in current codes.&lt;br /&gt;
* create_teams_view&lt;br /&gt;
* create_teams&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
The first piece of code is from student_team_controller.rb. It tests if there is already a same team name when student8 want to create a team. The second piece of code is from teams_controller_test.rb. It tests if the team number decreases when instructor1 creates a new team for a course.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, several parameters are needed. Usually we use four parameters: First, the method we are requesting. Second, an hash of request parameters for the method. Third, an optional hash of session variables. Forth, an optional hash of flash values. If we do not want to pass in the optional hash, we can set it to nil as the first piece of code shows, or we can just leave it blank as the second piece of code shows.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not. &lt;br /&gt;
&lt;br /&gt;
==Result==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Future Works==&lt;br /&gt;
===student_team_controller===&lt;br /&gt;
''Please note that this bug was reported fixed in the newest version of master branch of expertiza, but the fix came too late''&lt;br /&gt;
&lt;br /&gt;
There are several error raised from ''leave'' method need to be fixed, as mentioned above. Future teams may need to add tests on it as soon as it fixed, since it is a crucial functionality of the student team. &lt;br /&gt;
&lt;br /&gt;
Also, methods that seems like not being used, such as &amp;lt;code&amp;gt;advertise&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;remove_advertisement&amp;lt;/code&amp;gt; may need to be double checked and see if they are redundant.&lt;br /&gt;
===teams_controller===&lt;br /&gt;
The method &amp;lt;code&amp;gt;create_teams_view&amp;lt;/code&amp;gt; does not be used at all. So it is safe to delete it.&lt;br /&gt;
&lt;br /&gt;
The method &amp;lt;code&amp;gt;create_teams&amp;lt;/code&amp;gt; calls the method &amp;lt;code&amp;gt;randomize_all_by_parent&amp;lt;/code&amp;gt;, which is not correct. The developer may want to fix these bugs. &lt;br /&gt;
&lt;br /&gt;
It's possible that we can write more testing cases if we improve the fixture.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Qjia2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:QQ%E6%88%AA%E5%9B%BE20140409144837.png&amp;diff=84313</id>
		<title>File:QQ截图20140409144837.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:QQ%E6%88%AA%E5%9B%BE20140409144837.png&amp;diff=84313"/>
		<updated>2014-04-09T18:49:17Z</updated>

		<summary type="html">&lt;p&gt;Qjia2: user story&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;user story&lt;/div&gt;</summary>
		<author><name>Qjia2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:QQ%E6%88%AA%E5%9B%BE20140409144358.png&amp;diff=84312</id>
		<title>File:QQ截图20140409144358.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:QQ%E6%88%AA%E5%9B%BE20140409144358.png&amp;diff=84312"/>
		<updated>2014-04-09T18:46:31Z</updated>

		<summary type="html">&lt;p&gt;Qjia2: user story&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;user story&lt;/div&gt;</summary>
		<author><name>Qjia2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1414_st&amp;diff=84311</id>
		<title>CSC/ECE 517 Spring 2014/oss E1414 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1414_st&amp;diff=84311"/>
		<updated>2014-04-09T18:37:02Z</updated>

		<summary type="html">&lt;p&gt;Qjia2: /* app/models/teams_users.rb &amp;amp; app/controllers/teams_users_controller.rb = */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
==Classes==&lt;br /&gt;
=== app/controllers/teams_controller.rb ===&lt;br /&gt;
 &lt;br /&gt;
teams_controller contains functionalities for team management for instructor/TA accounts. &lt;br /&gt;
Instructor/TA can:&lt;br /&gt;
* view current teams&lt;br /&gt;
* create new teams&lt;br /&gt;
* import/export teams&lt;br /&gt;
* delete all teams/delete specified team&lt;br /&gt;
* copy existing teams from a course down to an assignment(inherit)&lt;br /&gt;
* update team's information&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/student_team_controller.rb ===&lt;br /&gt;
The student_team_controller support team management for student account.&lt;br /&gt;
student can&lt;br /&gt;
* create team&lt;br /&gt;
* view current team (including team invitations received and sent)&lt;br /&gt;
* advertise for their team&lt;br /&gt;
* remove the advertise for their team&lt;br /&gt;
* leave the team&lt;br /&gt;
&lt;br /&gt;
=== app/models/teams_users.rb===&lt;br /&gt;
The teams_users.rb is a model belonging to both users and teams. It is used when a user is added to a team.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_users_controller.rb===&lt;br /&gt;
The teams_users_controller support team member management for instructor/TA accounts&lt;br /&gt;
Instruction/TA can:&lt;br /&gt;
* get a user name by inputting part of the name&lt;br /&gt;
* list team members of a team &lt;br /&gt;
* add a user to a team&lt;br /&gt;
* remove a team member from a team&lt;br /&gt;
* remove all members belonging to an item&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb===&lt;br /&gt;
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.&lt;br /&gt;
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
To set up our testing for the models and controllers, we need some fixtures to support. &lt;br /&gt;
Fixtures needed for corresponding classes are listed below&lt;br /&gt;
&lt;br /&gt;
=== app/models/teams_users.rb &amp;amp; app/controllers/teams_users_controller.rb ===&lt;br /&gt;
* Teams.yml&lt;br /&gt;
* Usres.yml &lt;br /&gt;
* Teams_Uers.yml&lt;br /&gt;
* Courses.yml&lt;br /&gt;
* Assignments.yml&lt;br /&gt;
&lt;br /&gt;
== Tasks ==&lt;br /&gt;
Overall: contribute to the code coverage, ideally having overall coverage increase 2%&lt;br /&gt;
===student_team_controller===&lt;br /&gt;
* write tests&lt;br /&gt;
* def advertise_for_partners  # change to “advertise”&lt;br /&gt;
* def remove # change to “remove_advertisment”&lt;br /&gt;
* def review # remove this method&lt;br /&gt;
&lt;br /&gt;
===teams_controller===&lt;br /&gt;
* write tests&lt;br /&gt;
&lt;br /&gt;
== Deployment ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
To see the result of tests, run &lt;br /&gt;
 rake test TEST=test/functional/student_team_controller.rb&lt;br /&gt;
and &lt;br /&gt;
 rake test TEST=test/functional/teams_controller&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
;Total Number of Tests : 37&lt;br /&gt;
;Previous Coverage : 22.32%&lt;br /&gt;
;Current Coverage : 24.08% &lt;br /&gt;
&lt;br /&gt;
===Testing Scenarios===&lt;br /&gt;
====student_team_controller====&lt;br /&gt;
Most of the test case are straightforward. There are some of the test cases was commented out due to bug in the controller&lt;br /&gt;
* View student team (GET #view)&lt;br /&gt;
* Edit team (GET #edit)&lt;br /&gt;
* Create team with valid name (POST #create)&lt;br /&gt;
* Create team with name in use (POST #create)&lt;br /&gt;
* Update valid team name (POST #update) &lt;br /&gt;
* Update team name in use (POST #update)&lt;br /&gt;
* Update with current team name (POST #update)&lt;br /&gt;
* Advertise (GET #advertise)&lt;br /&gt;
''This is currently commented out in the committed code. It seems like the method is never called. It raises missing template error upon every call. ''&lt;br /&gt;
The &amp;lt;code&amp;gt;advertise&amp;lt;/code&amp;gt; method was previously named advertise_for_partners, but renamed due to ambiguity as there is another class with the same name. &lt;br /&gt;
&lt;br /&gt;
* Remove advertisement (GET #remove_advertisement )&lt;br /&gt;
The &amp;lt;code&amp;gt;remove_advertisement&amp;lt;/code&amp;gt; method was previously named remove, but renamed to avoid ambiguity&lt;br /&gt;
This method is never called as well, but it is functional as it do not require any template.&lt;br /&gt;
* Leave student team (GET #leave)&lt;br /&gt;
''This is currently commented out in the committed code, because it will raise error every time when called.''&lt;br /&gt;
It seems like problem happens on &lt;br /&gt;
  line 96: other_members = TeamsUser.where( ['team_id = ?', params[:team_id]]).first&lt;br /&gt;
  line 97: if other_members.length == 0&lt;br /&gt;
This will raise error due to the calling length of other_members, which is a single object but not an array.&lt;br /&gt;
Also, the related record seems to be remain undeleted in the database.&lt;br /&gt;
&lt;br /&gt;
====teams_controller====&lt;br /&gt;
Current test cases are as following.&lt;br /&gt;
* Create team should increase the number of teams by 1(GET #create)&lt;br /&gt;
* Create team should increase the number of team nodes by 1(GET #create)&lt;br /&gt;
* Create team with existing name (POST #create)&lt;br /&gt;
* Create team should redirect to list assignments (POST #create)&lt;br /&gt;
* Delete all teams (GET #delete_all)&lt;br /&gt;
* Delete all teams should redirect to list (GET #delete_all)&lt;br /&gt;
* List should receive assignment (GET #list)&lt;br /&gt;
* List should receive course (GET #list)&lt;br /&gt;
* New should assign parent (GET #new)&lt;br /&gt;
* Update team should redirect (POST #update)&lt;br /&gt;
* Update team should have validate name (POST #update)&lt;br /&gt;
* Edit team should have time (POST #edit)&lt;br /&gt;
* Delete team should redirect (POST #delete)&lt;br /&gt;
* Delete team should decrease the number of teams by 1(GET #delete)&lt;br /&gt;
* Delete team should decrease the number of team nodes by 1(GET #delete)&lt;br /&gt;
* Inherit team should redirect (POST #inherit)&lt;br /&gt;
* Bequeath team should redirect (POST #bequeath)&lt;br /&gt;
The methods in the following are ignored in testing since they are never used in current codes.&lt;br /&gt;
* create_teams_view&lt;br /&gt;
* create_teams&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
The first piece of code is from student_team_controller.rb. It tests if there is already a same team name when student8 want to create a team. The second piece of code is from teams_controller_test.rb. It tests if the team number decreases when instructor1 creates a new team for a course.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, several parameters are needed. Usually we use four parameters: First, the method we are requesting. Second, an hash of request parameters for the method. Third, an optional hash of session variables. Forth, an optional hash of flash values. If we do not want to pass in the optional hash, we can set it to nil as the first piece of code shows, or we can just leave it blank as the second piece of code shows.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not. &lt;br /&gt;
&lt;br /&gt;
==Result==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Future Works==&lt;br /&gt;
===student_team_controller===&lt;br /&gt;
''Please note that this bug was reported fixed in the newest version of master branch of expertiza, but the fix came too late''&lt;br /&gt;
&lt;br /&gt;
There are several error raised from ''leave'' method need to be fixed, as mentioned above. Future teams may need to add tests on it as soon as it fixed, since it is a crucial functionality of the student team. &lt;br /&gt;
&lt;br /&gt;
Also, methods that seems like not being used, such as &amp;lt;code&amp;gt;advertise&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;remove_advertisement&amp;lt;/code&amp;gt; may need to be double checked and see if they are redundant.&lt;br /&gt;
===teams_controller===&lt;br /&gt;
The method &amp;lt;code&amp;gt;create_teams_view&amp;lt;/code&amp;gt; does not be used at all. So it is safe to delete it.&lt;br /&gt;
&lt;br /&gt;
The method &amp;lt;code&amp;gt;create_teams&amp;lt;/code&amp;gt; calls the method &amp;lt;code&amp;gt;randomize_all_by_parent&amp;lt;/code&amp;gt;, which is not correct. The developer may want to fix these bugs. &lt;br /&gt;
&lt;br /&gt;
It's possible that we can write more testing cases if we improve the fixture.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Qjia2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1414_st&amp;diff=84310</id>
		<title>CSC/ECE 517 Spring 2014/oss E1414 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1414_st&amp;diff=84310"/>
		<updated>2014-04-09T18:36:44Z</updated>

		<summary type="html">&lt;p&gt;Qjia2: /* Setup */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
==Classes==&lt;br /&gt;
=== app/controllers/teams_controller.rb ===&lt;br /&gt;
 &lt;br /&gt;
teams_controller contains functionalities for team management for instructor/TA accounts. &lt;br /&gt;
Instructor/TA can:&lt;br /&gt;
* view current teams&lt;br /&gt;
* create new teams&lt;br /&gt;
* import/export teams&lt;br /&gt;
* delete all teams/delete specified team&lt;br /&gt;
* copy existing teams from a course down to an assignment(inherit)&lt;br /&gt;
* update team's information&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/student_team_controller.rb ===&lt;br /&gt;
The student_team_controller support team management for student account.&lt;br /&gt;
student can&lt;br /&gt;
* create team&lt;br /&gt;
* view current team (including team invitations received and sent)&lt;br /&gt;
* advertise for their team&lt;br /&gt;
* remove the advertise for their team&lt;br /&gt;
* leave the team&lt;br /&gt;
&lt;br /&gt;
=== app/models/teams_users.rb===&lt;br /&gt;
The teams_users.rb is a model belonging to both users and teams. It is used when a user is added to a team.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_users_controller.rb===&lt;br /&gt;
The teams_users_controller support team member management for instructor/TA accounts&lt;br /&gt;
Instruction/TA can:&lt;br /&gt;
* get a user name by inputting part of the name&lt;br /&gt;
* list team members of a team &lt;br /&gt;
* add a user to a team&lt;br /&gt;
* remove a team member from a team&lt;br /&gt;
* remove all members belonging to an item&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb===&lt;br /&gt;
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.&lt;br /&gt;
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
To set up our testing for the models and controllers, we need some fixtures to support. &lt;br /&gt;
Fixtures needed for corresponding classes are listed below&lt;br /&gt;
&lt;br /&gt;
== app/models/teams_users.rb &amp;amp; app/controllers/teams_users_controller.rb ===&lt;br /&gt;
* Teams.yml&lt;br /&gt;
* Usres.yml &lt;br /&gt;
* Teams_Uers.yml&lt;br /&gt;
* Courses.yml&lt;br /&gt;
* Assignments.yml&lt;br /&gt;
&lt;br /&gt;
== Tasks ==&lt;br /&gt;
Overall: contribute to the code coverage, ideally having overall coverage increase 2%&lt;br /&gt;
===student_team_controller===&lt;br /&gt;
* write tests&lt;br /&gt;
* def advertise_for_partners  # change to “advertise”&lt;br /&gt;
* def remove # change to “remove_advertisment”&lt;br /&gt;
* def review # remove this method&lt;br /&gt;
&lt;br /&gt;
===teams_controller===&lt;br /&gt;
* write tests&lt;br /&gt;
&lt;br /&gt;
== Deployment ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
To see the result of tests, run &lt;br /&gt;
 rake test TEST=test/functional/student_team_controller.rb&lt;br /&gt;
and &lt;br /&gt;
 rake test TEST=test/functional/teams_controller&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
;Total Number of Tests : 37&lt;br /&gt;
;Previous Coverage : 22.32%&lt;br /&gt;
;Current Coverage : 24.08% &lt;br /&gt;
&lt;br /&gt;
===Testing Scenarios===&lt;br /&gt;
====student_team_controller====&lt;br /&gt;
Most of the test case are straightforward. There are some of the test cases was commented out due to bug in the controller&lt;br /&gt;
* View student team (GET #view)&lt;br /&gt;
* Edit team (GET #edit)&lt;br /&gt;
* Create team with valid name (POST #create)&lt;br /&gt;
* Create team with name in use (POST #create)&lt;br /&gt;
* Update valid team name (POST #update) &lt;br /&gt;
* Update team name in use (POST #update)&lt;br /&gt;
* Update with current team name (POST #update)&lt;br /&gt;
* Advertise (GET #advertise)&lt;br /&gt;
''This is currently commented out in the committed code. It seems like the method is never called. It raises missing template error upon every call. ''&lt;br /&gt;
The &amp;lt;code&amp;gt;advertise&amp;lt;/code&amp;gt; method was previously named advertise_for_partners, but renamed due to ambiguity as there is another class with the same name. &lt;br /&gt;
&lt;br /&gt;
* Remove advertisement (GET #remove_advertisement )&lt;br /&gt;
The &amp;lt;code&amp;gt;remove_advertisement&amp;lt;/code&amp;gt; method was previously named remove, but renamed to avoid ambiguity&lt;br /&gt;
This method is never called as well, but it is functional as it do not require any template.&lt;br /&gt;
* Leave student team (GET #leave)&lt;br /&gt;
''This is currently commented out in the committed code, because it will raise error every time when called.''&lt;br /&gt;
It seems like problem happens on &lt;br /&gt;
  line 96: other_members = TeamsUser.where( ['team_id = ?', params[:team_id]]).first&lt;br /&gt;
  line 97: if other_members.length == 0&lt;br /&gt;
This will raise error due to the calling length of other_members, which is a single object but not an array.&lt;br /&gt;
Also, the related record seems to be remain undeleted in the database.&lt;br /&gt;
&lt;br /&gt;
====teams_controller====&lt;br /&gt;
Current test cases are as following.&lt;br /&gt;
* Create team should increase the number of teams by 1(GET #create)&lt;br /&gt;
* Create team should increase the number of team nodes by 1(GET #create)&lt;br /&gt;
* Create team with existing name (POST #create)&lt;br /&gt;
* Create team should redirect to list assignments (POST #create)&lt;br /&gt;
* Delete all teams (GET #delete_all)&lt;br /&gt;
* Delete all teams should redirect to list (GET #delete_all)&lt;br /&gt;
* List should receive assignment (GET #list)&lt;br /&gt;
* List should receive course (GET #list)&lt;br /&gt;
* New should assign parent (GET #new)&lt;br /&gt;
* Update team should redirect (POST #update)&lt;br /&gt;
* Update team should have validate name (POST #update)&lt;br /&gt;
* Edit team should have time (POST #edit)&lt;br /&gt;
* Delete team should redirect (POST #delete)&lt;br /&gt;
* Delete team should decrease the number of teams by 1(GET #delete)&lt;br /&gt;
* Delete team should decrease the number of team nodes by 1(GET #delete)&lt;br /&gt;
* Inherit team should redirect (POST #inherit)&lt;br /&gt;
* Bequeath team should redirect (POST #bequeath)&lt;br /&gt;
The methods in the following are ignored in testing since they are never used in current codes.&lt;br /&gt;
* create_teams_view&lt;br /&gt;
* create_teams&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
The first piece of code is from student_team_controller.rb. It tests if there is already a same team name when student8 want to create a team. The second piece of code is from teams_controller_test.rb. It tests if the team number decreases when instructor1 creates a new team for a course.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, several parameters are needed. Usually we use four parameters: First, the method we are requesting. Second, an hash of request parameters for the method. Third, an optional hash of session variables. Forth, an optional hash of flash values. If we do not want to pass in the optional hash, we can set it to nil as the first piece of code shows, or we can just leave it blank as the second piece of code shows.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not. &lt;br /&gt;
&lt;br /&gt;
==Result==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Future Works==&lt;br /&gt;
===student_team_controller===&lt;br /&gt;
''Please note that this bug was reported fixed in the newest version of master branch of expertiza, but the fix came too late''&lt;br /&gt;
&lt;br /&gt;
There are several error raised from ''leave'' method need to be fixed, as mentioned above. Future teams may need to add tests on it as soon as it fixed, since it is a crucial functionality of the student team. &lt;br /&gt;
&lt;br /&gt;
Also, methods that seems like not being used, such as &amp;lt;code&amp;gt;advertise&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;remove_advertisement&amp;lt;/code&amp;gt; may need to be double checked and see if they are redundant.&lt;br /&gt;
===teams_controller===&lt;br /&gt;
The method &amp;lt;code&amp;gt;create_teams_view&amp;lt;/code&amp;gt; does not be used at all. So it is safe to delete it.&lt;br /&gt;
&lt;br /&gt;
The method &amp;lt;code&amp;gt;create_teams&amp;lt;/code&amp;gt; calls the method &amp;lt;code&amp;gt;randomize_all_by_parent&amp;lt;/code&amp;gt;, which is not correct. The developer may want to fix these bugs. &lt;br /&gt;
&lt;br /&gt;
It's possible that we can write more testing cases if we improve the fixture.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Qjia2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1414_st&amp;diff=84309</id>
		<title>CSC/ECE 517 Spring 2014/oss E1414 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1414_st&amp;diff=84309"/>
		<updated>2014-04-09T18:33:17Z</updated>

		<summary type="html">&lt;p&gt;Qjia2: /* E1414: Testing classes related to teams */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
==Classes==&lt;br /&gt;
=== app/controllers/teams_controller.rb ===&lt;br /&gt;
 &lt;br /&gt;
teams_controller contains functionalities for team management for instructor/TA accounts. &lt;br /&gt;
Instructor/TA can:&lt;br /&gt;
* view current teams&lt;br /&gt;
* create new teams&lt;br /&gt;
* import/export teams&lt;br /&gt;
* delete all teams/delete specified team&lt;br /&gt;
* copy existing teams from a course down to an assignment(inherit)&lt;br /&gt;
* update team's information&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/student_team_controller.rb ===&lt;br /&gt;
The student_team_controller support team management for student account.&lt;br /&gt;
student can&lt;br /&gt;
* create team&lt;br /&gt;
* view current team (including team invitations received and sent)&lt;br /&gt;
* advertise for their team&lt;br /&gt;
* remove the advertise for their team&lt;br /&gt;
* leave the team&lt;br /&gt;
&lt;br /&gt;
=== app/models/teams_users.rb===&lt;br /&gt;
The teams_users.rb is a model belonging to both users and teams. It is used when a user is added to a team.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_users_controller.rb===&lt;br /&gt;
The teams_users_controller support team member management for instructor/TA accounts&lt;br /&gt;
Instruction/TA can:&lt;br /&gt;
* get a user name by inputting part of the name&lt;br /&gt;
* list team members of a team &lt;br /&gt;
* add a user to a team&lt;br /&gt;
* remove a team member from a team&lt;br /&gt;
* remove all members belonging to an item&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb===&lt;br /&gt;
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.&lt;br /&gt;
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
== Tasks ==&lt;br /&gt;
Overall: contribute to the code coverage, ideally having overall coverage increase 2%&lt;br /&gt;
===student_team_controller===&lt;br /&gt;
* write tests&lt;br /&gt;
* def advertise_for_partners  # change to “advertise”&lt;br /&gt;
* def remove # change to “remove_advertisment”&lt;br /&gt;
* def review # remove this method&lt;br /&gt;
&lt;br /&gt;
===teams_controller===&lt;br /&gt;
* write tests&lt;br /&gt;
&lt;br /&gt;
== Deployment ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
To see the result of tests, run &lt;br /&gt;
 rake test TEST=test/functional/student_team_controller.rb&lt;br /&gt;
and &lt;br /&gt;
 rake test TEST=test/functional/teams_controller&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
;Total Number of Tests : 37&lt;br /&gt;
;Previous Coverage : 22.32%&lt;br /&gt;
;Current Coverage : 24.08% &lt;br /&gt;
&lt;br /&gt;
===Testing Scenarios===&lt;br /&gt;
====student_team_controller====&lt;br /&gt;
Most of the test case are straightforward. There are some of the test cases was commented out due to bug in the controller&lt;br /&gt;
* View student team (GET #view)&lt;br /&gt;
* Edit team (GET #edit)&lt;br /&gt;
* Create team with valid name (POST #create)&lt;br /&gt;
* Create team with name in use (POST #create)&lt;br /&gt;
* Update valid team name (POST #update) &lt;br /&gt;
* Update team name in use (POST #update)&lt;br /&gt;
* Update with current team name (POST #update)&lt;br /&gt;
* Advertise (GET #advertise)&lt;br /&gt;
''This is currently commented out in the committed code. It seems like the method is never called. It raises missing template error upon every call. ''&lt;br /&gt;
The &amp;lt;code&amp;gt;advertise&amp;lt;/code&amp;gt; method was previously named advertise_for_partners, but renamed due to ambiguity as there is another class with the same name. &lt;br /&gt;
&lt;br /&gt;
* Remove advertisement (GET #remove_advertisement )&lt;br /&gt;
The &amp;lt;code&amp;gt;remove_advertisement&amp;lt;/code&amp;gt; method was previously named remove, but renamed to avoid ambiguity&lt;br /&gt;
This method is never called as well, but it is functional as it do not require any template.&lt;br /&gt;
* Leave student team (GET #leave)&lt;br /&gt;
''This is currently commented out in the committed code, because it will raise error every time when called.''&lt;br /&gt;
It seems like problem happens on &lt;br /&gt;
  line 96: other_members = TeamsUser.where( ['team_id = ?', params[:team_id]]).first&lt;br /&gt;
  line 97: if other_members.length == 0&lt;br /&gt;
This will raise error due to the calling length of other_members, which is a single object but not an array.&lt;br /&gt;
Also, the related record seems to be remain undeleted in the database.&lt;br /&gt;
&lt;br /&gt;
====teams_controller====&lt;br /&gt;
Current test cases are as following.&lt;br /&gt;
* Create team should increase the number of teams by 1(GET #create)&lt;br /&gt;
* Create team should increase the number of team nodes by 1(GET #create)&lt;br /&gt;
* Create team with existing name (POST #create)&lt;br /&gt;
* Create team should redirect to list assignments (POST #create)&lt;br /&gt;
* Delete all teams (GET #delete_all)&lt;br /&gt;
* Delete all teams should redirect to list (GET #delete_all)&lt;br /&gt;
* List should receive assignment (GET #list)&lt;br /&gt;
* List should receive course (GET #list)&lt;br /&gt;
* New should assign parent (GET #new)&lt;br /&gt;
* Update team should redirect (POST #update)&lt;br /&gt;
* Update team should have validate name (POST #update)&lt;br /&gt;
* Edit team should have time (POST #edit)&lt;br /&gt;
* Delete team should redirect (POST #delete)&lt;br /&gt;
* Delete team should decrease the number of teams by 1(GET #delete)&lt;br /&gt;
* Delete team should decrease the number of team nodes by 1(GET #delete)&lt;br /&gt;
* Inherit team should redirect (POST #inherit)&lt;br /&gt;
* Bequeath team should redirect (POST #bequeath)&lt;br /&gt;
The methods in the following are ignored in testing since they are never used in current codes.&lt;br /&gt;
* create_teams_view&lt;br /&gt;
* create_teams&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
The first piece of code is from student_team_controller.rb. It tests if there is already a same team name when student8 want to create a team. The second piece of code is from teams_controller_test.rb. It tests if the team number decreases when instructor1 creates a new team for a course.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, several parameters are needed. Usually we use four parameters: First, the method we are requesting. Second, an hash of request parameters for the method. Third, an optional hash of session variables. Forth, an optional hash of flash values. If we do not want to pass in the optional hash, we can set it to nil as the first piece of code shows, or we can just leave it blank as the second piece of code shows.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not. &lt;br /&gt;
&lt;br /&gt;
==Result==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Future Works==&lt;br /&gt;
===student_team_controller===&lt;br /&gt;
''Please note that this bug was reported fixed in the newest version of master branch of expertiza, but the fix came too late''&lt;br /&gt;
&lt;br /&gt;
There are several error raised from ''leave'' method need to be fixed, as mentioned above. Future teams may need to add tests on it as soon as it fixed, since it is a crucial functionality of the student team. &lt;br /&gt;
&lt;br /&gt;
Also, methods that seems like not being used, such as &amp;lt;code&amp;gt;advertise&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;remove_advertisement&amp;lt;/code&amp;gt; may need to be double checked and see if they are redundant.&lt;br /&gt;
===teams_controller===&lt;br /&gt;
The method &amp;lt;code&amp;gt;create_teams_view&amp;lt;/code&amp;gt; does not be used at all. So it is safe to delete it.&lt;br /&gt;
&lt;br /&gt;
The method &amp;lt;code&amp;gt;create_teams&amp;lt;/code&amp;gt; calls the method &amp;lt;code&amp;gt;randomize_all_by_parent&amp;lt;/code&amp;gt;, which is not correct. The developer may want to fix these bugs. &lt;br /&gt;
&lt;br /&gt;
It's possible that we can write more testing cases if we improve the fixture.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Qjia2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1414_st&amp;diff=84308</id>
		<title>CSC/ECE 517 Spring 2014/oss E1414 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1414_st&amp;diff=84308"/>
		<updated>2014-04-09T18:32:20Z</updated>

		<summary type="html">&lt;p&gt;Qjia2: /* Classes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
==Classes==&lt;br /&gt;
=== app/controllers/teams_controller.rb ===&lt;br /&gt;
 &lt;br /&gt;
teams_controller contains functionalities for team management for instructor/TA accounts. &lt;br /&gt;
Instructor/TA can:&lt;br /&gt;
* view current teams&lt;br /&gt;
* create new teams&lt;br /&gt;
* import/export teams&lt;br /&gt;
* delete all teams/delete specified team&lt;br /&gt;
* copy existing teams from a course down to an assignment(inherit)&lt;br /&gt;
* update team's information&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/student_team_controller.rb ===&lt;br /&gt;
The student_team_controller support team management for student account.&lt;br /&gt;
student can&lt;br /&gt;
* create team&lt;br /&gt;
* view current team (including team invitations received and sent)&lt;br /&gt;
* advertise for their team&lt;br /&gt;
* remove the advertise for their team&lt;br /&gt;
* leave the team&lt;br /&gt;
&lt;br /&gt;
=== app/models/teams_users.rb===&lt;br /&gt;
The teams_users.rb is a model belonging to both users and teams. It is used when a user is added to a team.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_users_controller.rb===&lt;br /&gt;
The teams_users_controller support team member management for instructor/TA accounts&lt;br /&gt;
Instruction/TA can:&lt;br /&gt;
* get a user name by inputting part of the name&lt;br /&gt;
* list team members of a team &lt;br /&gt;
* add a user to a team&lt;br /&gt;
* remove a team member from a team&lt;br /&gt;
* remove all members belonging to an item&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb===&lt;br /&gt;
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.&lt;br /&gt;
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.&lt;br /&gt;
&lt;br /&gt;
== Tasks ==&lt;br /&gt;
Overall: contribute to the code coverage, ideally having overall coverage increase 2%&lt;br /&gt;
===student_team_controller===&lt;br /&gt;
* write tests&lt;br /&gt;
* def advertise_for_partners  # change to “advertise”&lt;br /&gt;
* def remove # change to “remove_advertisment”&lt;br /&gt;
* def review # remove this method&lt;br /&gt;
&lt;br /&gt;
===teams_controller===&lt;br /&gt;
* write tests&lt;br /&gt;
&lt;br /&gt;
== Deployment ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
To see the result of tests, run &lt;br /&gt;
 rake test TEST=test/functional/student_team_controller.rb&lt;br /&gt;
and &lt;br /&gt;
 rake test TEST=test/functional/teams_controller&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
;Total Number of Tests : 37&lt;br /&gt;
;Previous Coverage : 22.32%&lt;br /&gt;
;Current Coverage : 24.08% &lt;br /&gt;
&lt;br /&gt;
===Testing Scenarios===&lt;br /&gt;
====student_team_controller====&lt;br /&gt;
Most of the test case are straightforward. There are some of the test cases was commented out due to bug in the controller&lt;br /&gt;
* View student team (GET #view)&lt;br /&gt;
* Edit team (GET #edit)&lt;br /&gt;
* Create team with valid name (POST #create)&lt;br /&gt;
* Create team with name in use (POST #create)&lt;br /&gt;
* Update valid team name (POST #update) &lt;br /&gt;
* Update team name in use (POST #update)&lt;br /&gt;
* Update with current team name (POST #update)&lt;br /&gt;
* Advertise (GET #advertise)&lt;br /&gt;
''This is currently commented out in the committed code. It seems like the method is never called. It raises missing template error upon every call. ''&lt;br /&gt;
The &amp;lt;code&amp;gt;advertise&amp;lt;/code&amp;gt; method was previously named advertise_for_partners, but renamed due to ambiguity as there is another class with the same name. &lt;br /&gt;
&lt;br /&gt;
* Remove advertisement (GET #remove_advertisement )&lt;br /&gt;
The &amp;lt;code&amp;gt;remove_advertisement&amp;lt;/code&amp;gt; method was previously named remove, but renamed to avoid ambiguity&lt;br /&gt;
This method is never called as well, but it is functional as it do not require any template.&lt;br /&gt;
* Leave student team (GET #leave)&lt;br /&gt;
''This is currently commented out in the committed code, because it will raise error every time when called.''&lt;br /&gt;
It seems like problem happens on &lt;br /&gt;
  line 96: other_members = TeamsUser.where( ['team_id = ?', params[:team_id]]).first&lt;br /&gt;
  line 97: if other_members.length == 0&lt;br /&gt;
This will raise error due to the calling length of other_members, which is a single object but not an array.&lt;br /&gt;
Also, the related record seems to be remain undeleted in the database.&lt;br /&gt;
&lt;br /&gt;
====teams_controller====&lt;br /&gt;
Current test cases are as following.&lt;br /&gt;
* Create team should increase the number of teams by 1(GET #create)&lt;br /&gt;
* Create team should increase the number of team nodes by 1(GET #create)&lt;br /&gt;
* Create team with existing name (POST #create)&lt;br /&gt;
* Create team should redirect to list assignments (POST #create)&lt;br /&gt;
* Delete all teams (GET #delete_all)&lt;br /&gt;
* Delete all teams should redirect to list (GET #delete_all)&lt;br /&gt;
* List should receive assignment (GET #list)&lt;br /&gt;
* List should receive course (GET #list)&lt;br /&gt;
* New should assign parent (GET #new)&lt;br /&gt;
* Update team should redirect (POST #update)&lt;br /&gt;
* Update team should have validate name (POST #update)&lt;br /&gt;
* Edit team should have time (POST #edit)&lt;br /&gt;
* Delete team should redirect (POST #delete)&lt;br /&gt;
* Delete team should decrease the number of teams by 1(GET #delete)&lt;br /&gt;
* Delete team should decrease the number of team nodes by 1(GET #delete)&lt;br /&gt;
* Inherit team should redirect (POST #inherit)&lt;br /&gt;
* Bequeath team should redirect (POST #bequeath)&lt;br /&gt;
The methods in the following are ignored in testing since they are never used in current codes.&lt;br /&gt;
* create_teams_view&lt;br /&gt;
* create_teams&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
The first piece of code is from student_team_controller.rb. It tests if there is already a same team name when student8 want to create a team. The second piece of code is from teams_controller_test.rb. It tests if the team number decreases when instructor1 creates a new team for a course.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, several parameters are needed. Usually we use four parameters: First, the method we are requesting. Second, an hash of request parameters for the method. Third, an optional hash of session variables. Forth, an optional hash of flash values. If we do not want to pass in the optional hash, we can set it to nil as the first piece of code shows, or we can just leave it blank as the second piece of code shows.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not. &lt;br /&gt;
&lt;br /&gt;
==Result==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Future Works==&lt;br /&gt;
===student_team_controller===&lt;br /&gt;
''Please note that this bug was reported fixed in the newest version of master branch of expertiza, but the fix came too late''&lt;br /&gt;
&lt;br /&gt;
There are several error raised from ''leave'' method need to be fixed, as mentioned above. Future teams may need to add tests on it as soon as it fixed, since it is a crucial functionality of the student team. &lt;br /&gt;
&lt;br /&gt;
Also, methods that seems like not being used, such as &amp;lt;code&amp;gt;advertise&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;remove_advertisement&amp;lt;/code&amp;gt; may need to be double checked and see if they are redundant.&lt;br /&gt;
===teams_controller===&lt;br /&gt;
The method &amp;lt;code&amp;gt;create_teams_view&amp;lt;/code&amp;gt; does not be used at all. So it is safe to delete it.&lt;br /&gt;
&lt;br /&gt;
The method &amp;lt;code&amp;gt;create_teams&amp;lt;/code&amp;gt; calls the method &amp;lt;code&amp;gt;randomize_all_by_parent&amp;lt;/code&amp;gt;, which is not correct. The developer may want to fix these bugs. &lt;br /&gt;
&lt;br /&gt;
It's possible that we can write more testing cases if we improve the fixture.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Qjia2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1414_st&amp;diff=84307</id>
		<title>CSC/ECE 517 Spring 2014/oss E1414 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1414_st&amp;diff=84307"/>
		<updated>2014-04-09T18:29:22Z</updated>

		<summary type="html">&lt;p&gt;Qjia2: /* Motivation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
==Classes==&lt;br /&gt;
=== app/controllers/teams_controller.rb ===&lt;br /&gt;
 &lt;br /&gt;
teams_controller contains functionalities for team management for instructor/TA accounts. &lt;br /&gt;
Instructor/TA can:&lt;br /&gt;
* view current teams&lt;br /&gt;
* create new teams&lt;br /&gt;
* import/export teams&lt;br /&gt;
* delete all teams/delete specified team&lt;br /&gt;
* copy existing teams from a course down to an assignment(inherit)&lt;br /&gt;
* update team's information&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/student_team_controller.rb ===&lt;br /&gt;
The student_team_controller support team management for student account.&lt;br /&gt;
student can&lt;br /&gt;
* create team&lt;br /&gt;
* view current team (including team invitations received and sent)&lt;br /&gt;
* advertise for their team&lt;br /&gt;
* remove the advertise for their team&lt;br /&gt;
* leave the team&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_users_controller.rb===&lt;br /&gt;
The teams_users_controller support team member management for instructor/TA accounts&lt;br /&gt;
Instruction/TA can:&lt;br /&gt;
* get a user name by inputting part of the name&lt;br /&gt;
* list team members of a team &lt;br /&gt;
* add a user to a team&lt;br /&gt;
* remove a team member from a team&lt;br /&gt;
* remove all members belonging to an item&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb===&lt;br /&gt;
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.&lt;br /&gt;
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.&lt;br /&gt;
&lt;br /&gt;
== Tasks ==&lt;br /&gt;
Overall: contribute to the code coverage, ideally having overall coverage increase 2%&lt;br /&gt;
===student_team_controller===&lt;br /&gt;
* write tests&lt;br /&gt;
* def advertise_for_partners  # change to “advertise”&lt;br /&gt;
* def remove # change to “remove_advertisment”&lt;br /&gt;
* def review # remove this method&lt;br /&gt;
&lt;br /&gt;
===teams_controller===&lt;br /&gt;
* write tests&lt;br /&gt;
&lt;br /&gt;
== Deployment ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
To see the result of tests, run &lt;br /&gt;
 rake test TEST=test/functional/student_team_controller.rb&lt;br /&gt;
and &lt;br /&gt;
 rake test TEST=test/functional/teams_controller&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
;Total Number of Tests : 37&lt;br /&gt;
;Previous Coverage : 22.32%&lt;br /&gt;
;Current Coverage : 24.08% &lt;br /&gt;
&lt;br /&gt;
===Testing Scenarios===&lt;br /&gt;
====student_team_controller====&lt;br /&gt;
Most of the test case are straightforward. There are some of the test cases was commented out due to bug in the controller&lt;br /&gt;
* View student team (GET #view)&lt;br /&gt;
* Edit team (GET #edit)&lt;br /&gt;
* Create team with valid name (POST #create)&lt;br /&gt;
* Create team with name in use (POST #create)&lt;br /&gt;
* Update valid team name (POST #update) &lt;br /&gt;
* Update team name in use (POST #update)&lt;br /&gt;
* Update with current team name (POST #update)&lt;br /&gt;
* Advertise (GET #advertise)&lt;br /&gt;
''This is currently commented out in the committed code. It seems like the method is never called. It raises missing template error upon every call. ''&lt;br /&gt;
The &amp;lt;code&amp;gt;advertise&amp;lt;/code&amp;gt; method was previously named advertise_for_partners, but renamed due to ambiguity as there is another class with the same name. &lt;br /&gt;
&lt;br /&gt;
* Remove advertisement (GET #remove_advertisement )&lt;br /&gt;
The &amp;lt;code&amp;gt;remove_advertisement&amp;lt;/code&amp;gt; method was previously named remove, but renamed to avoid ambiguity&lt;br /&gt;
This method is never called as well, but it is functional as it do not require any template.&lt;br /&gt;
* Leave student team (GET #leave)&lt;br /&gt;
''This is currently commented out in the committed code, because it will raise error every time when called.''&lt;br /&gt;
It seems like problem happens on &lt;br /&gt;
  line 96: other_members = TeamsUser.where( ['team_id = ?', params[:team_id]]).first&lt;br /&gt;
  line 97: if other_members.length == 0&lt;br /&gt;
This will raise error due to the calling length of other_members, which is a single object but not an array.&lt;br /&gt;
Also, the related record seems to be remain undeleted in the database.&lt;br /&gt;
&lt;br /&gt;
====teams_controller====&lt;br /&gt;
Current test cases are as following.&lt;br /&gt;
* Create team should increase the number of teams by 1(GET #create)&lt;br /&gt;
* Create team should increase the number of team nodes by 1(GET #create)&lt;br /&gt;
* Create team with existing name (POST #create)&lt;br /&gt;
* Create team should redirect to list assignments (POST #create)&lt;br /&gt;
* Delete all teams (GET #delete_all)&lt;br /&gt;
* Delete all teams should redirect to list (GET #delete_all)&lt;br /&gt;
* List should receive assignment (GET #list)&lt;br /&gt;
* List should receive course (GET #list)&lt;br /&gt;
* New should assign parent (GET #new)&lt;br /&gt;
* Update team should redirect (POST #update)&lt;br /&gt;
* Update team should have validate name (POST #update)&lt;br /&gt;
* Edit team should have time (POST #edit)&lt;br /&gt;
* Delete team should redirect (POST #delete)&lt;br /&gt;
* Delete team should decrease the number of teams by 1(GET #delete)&lt;br /&gt;
* Delete team should decrease the number of team nodes by 1(GET #delete)&lt;br /&gt;
* Inherit team should redirect (POST #inherit)&lt;br /&gt;
* Bequeath team should redirect (POST #bequeath)&lt;br /&gt;
The methods in the following are ignored in testing since they are never used in current codes.&lt;br /&gt;
* create_teams_view&lt;br /&gt;
* create_teams&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
The first piece of code is from student_team_controller.rb. It tests if there is already a same team name when student8 want to create a team. The second piece of code is from teams_controller_test.rb. It tests if the team number decreases when instructor1 creates a new team for a course.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, several parameters are needed. Usually we use four parameters: First, the method we are requesting. Second, an hash of request parameters for the method. Third, an optional hash of session variables. Forth, an optional hash of flash values. If we do not want to pass in the optional hash, we can set it to nil as the first piece of code shows, or we can just leave it blank as the second piece of code shows.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not. &lt;br /&gt;
&lt;br /&gt;
==Result==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Future Works==&lt;br /&gt;
===student_team_controller===&lt;br /&gt;
''Please note that this bug was reported fixed in the newest version of master branch of expertiza, but the fix came too late''&lt;br /&gt;
&lt;br /&gt;
There are several error raised from ''leave'' method need to be fixed, as mentioned above. Future teams may need to add tests on it as soon as it fixed, since it is a crucial functionality of the student team. &lt;br /&gt;
&lt;br /&gt;
Also, methods that seems like not being used, such as &amp;lt;code&amp;gt;advertise&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;remove_advertisement&amp;lt;/code&amp;gt; may need to be double checked and see if they are redundant.&lt;br /&gt;
===teams_controller===&lt;br /&gt;
The method &amp;lt;code&amp;gt;create_teams_view&amp;lt;/code&amp;gt; does not be used at all. So it is safe to delete it.&lt;br /&gt;
&lt;br /&gt;
The method &amp;lt;code&amp;gt;create_teams&amp;lt;/code&amp;gt; calls the method &amp;lt;code&amp;gt;randomize_all_by_parent&amp;lt;/code&amp;gt;, which is not correct. The developer may want to fix these bugs. &lt;br /&gt;
&lt;br /&gt;
It's possible that we can write more testing cases if we improve the fixture.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Qjia2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1414_st&amp;diff=84306</id>
		<title>CSC/ECE 517 Spring 2014/oss E1414 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1414_st&amp;diff=84306"/>
		<updated>2014-04-09T18:25:42Z</updated>

		<summary type="html">&lt;p&gt;Qjia2: /* Classes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
==Classes==&lt;br /&gt;
=== app/controllers/teams_controller.rb ===&lt;br /&gt;
 &lt;br /&gt;
teams_controller contains functionalities for team management for instructor/TA accounts. &lt;br /&gt;
Instructor/TA can:&lt;br /&gt;
* view current teams&lt;br /&gt;
* create new teams&lt;br /&gt;
* import/export teams&lt;br /&gt;
* delete all teams/delete specified team&lt;br /&gt;
* copy existing teams from a course down to an assignment(inherit)&lt;br /&gt;
* update team's information&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/student_team_controller.rb ===&lt;br /&gt;
The student_team_controller support team management for student account.&lt;br /&gt;
student can&lt;br /&gt;
* create team&lt;br /&gt;
* view current team (including team invitations received and sent)&lt;br /&gt;
* advertise for their team&lt;br /&gt;
* remove the advertise for their team&lt;br /&gt;
* leave the team&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_users_controller.rb===&lt;br /&gt;
The teams_users_controller support team member management for instructor/TA accounts&lt;br /&gt;
Instruction/TA can:&lt;br /&gt;
* get a user name by inputting part of the name&lt;br /&gt;
* list team members of a team &lt;br /&gt;
* add a user to a team&lt;br /&gt;
* remove a team member from a team&lt;br /&gt;
* remove all members belonging to an item&lt;br /&gt;
&lt;br /&gt;
== Motivation ==&lt;br /&gt;
There were no functional tests written on the two controllers to detect bugs, as well as confirming they are functional by itself and after integration.&lt;br /&gt;
&lt;br /&gt;
Our goal is to add comprehensive functional tests and integration tests to the two controllers to provide a preferable test suite for the future developers. &lt;br /&gt;
&lt;br /&gt;
Also, as the classes are influenced by the changes from other, we are also responsible for fixing some of the bugs, refactoring the method names to a better ones, as well as reporting the bugs found in the testing process.&lt;br /&gt;
&lt;br /&gt;
== Tasks ==&lt;br /&gt;
Overall: contribute to the code coverage, ideally having overall coverage increase 2%&lt;br /&gt;
===student_team_controller===&lt;br /&gt;
* write tests&lt;br /&gt;
* def advertise_for_partners  # change to “advertise”&lt;br /&gt;
* def remove # change to “remove_advertisment”&lt;br /&gt;
* def review # remove this method&lt;br /&gt;
&lt;br /&gt;
===teams_controller===&lt;br /&gt;
* write tests&lt;br /&gt;
&lt;br /&gt;
== Deployment ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
To see the result of tests, run &lt;br /&gt;
 rake test TEST=test/functional/student_team_controller.rb&lt;br /&gt;
and &lt;br /&gt;
 rake test TEST=test/functional/teams_controller&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
;Total Number of Tests : 37&lt;br /&gt;
;Previous Coverage : 22.32%&lt;br /&gt;
;Current Coverage : 24.08% &lt;br /&gt;
&lt;br /&gt;
===Testing Scenarios===&lt;br /&gt;
====student_team_controller====&lt;br /&gt;
Most of the test case are straightforward. There are some of the test cases was commented out due to bug in the controller&lt;br /&gt;
* View student team (GET #view)&lt;br /&gt;
* Edit team (GET #edit)&lt;br /&gt;
* Create team with valid name (POST #create)&lt;br /&gt;
* Create team with name in use (POST #create)&lt;br /&gt;
* Update valid team name (POST #update) &lt;br /&gt;
* Update team name in use (POST #update)&lt;br /&gt;
* Update with current team name (POST #update)&lt;br /&gt;
* Advertise (GET #advertise)&lt;br /&gt;
''This is currently commented out in the committed code. It seems like the method is never called. It raises missing template error upon every call. ''&lt;br /&gt;
The &amp;lt;code&amp;gt;advertise&amp;lt;/code&amp;gt; method was previously named advertise_for_partners, but renamed due to ambiguity as there is another class with the same name. &lt;br /&gt;
&lt;br /&gt;
* Remove advertisement (GET #remove_advertisement )&lt;br /&gt;
The &amp;lt;code&amp;gt;remove_advertisement&amp;lt;/code&amp;gt; method was previously named remove, but renamed to avoid ambiguity&lt;br /&gt;
This method is never called as well, but it is functional as it do not require any template.&lt;br /&gt;
* Leave student team (GET #leave)&lt;br /&gt;
''This is currently commented out in the committed code, because it will raise error every time when called.''&lt;br /&gt;
It seems like problem happens on &lt;br /&gt;
  line 96: other_members = TeamsUser.where( ['team_id = ?', params[:team_id]]).first&lt;br /&gt;
  line 97: if other_members.length == 0&lt;br /&gt;
This will raise error due to the calling length of other_members, which is a single object but not an array.&lt;br /&gt;
Also, the related record seems to be remain undeleted in the database.&lt;br /&gt;
&lt;br /&gt;
====teams_controller====&lt;br /&gt;
Current test cases are as following.&lt;br /&gt;
* Create team should increase the number of teams by 1(GET #create)&lt;br /&gt;
* Create team should increase the number of team nodes by 1(GET #create)&lt;br /&gt;
* Create team with existing name (POST #create)&lt;br /&gt;
* Create team should redirect to list assignments (POST #create)&lt;br /&gt;
* Delete all teams (GET #delete_all)&lt;br /&gt;
* Delete all teams should redirect to list (GET #delete_all)&lt;br /&gt;
* List should receive assignment (GET #list)&lt;br /&gt;
* List should receive course (GET #list)&lt;br /&gt;
* New should assign parent (GET #new)&lt;br /&gt;
* Update team should redirect (POST #update)&lt;br /&gt;
* Update team should have validate name (POST #update)&lt;br /&gt;
* Edit team should have time (POST #edit)&lt;br /&gt;
* Delete team should redirect (POST #delete)&lt;br /&gt;
* Delete team should decrease the number of teams by 1(GET #delete)&lt;br /&gt;
* Delete team should decrease the number of team nodes by 1(GET #delete)&lt;br /&gt;
* Inherit team should redirect (POST #inherit)&lt;br /&gt;
* Bequeath team should redirect (POST #bequeath)&lt;br /&gt;
The methods in the following are ignored in testing since they are never used in current codes.&lt;br /&gt;
* create_teams_view&lt;br /&gt;
* create_teams&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
The first piece of code is from student_team_controller.rb. It tests if there is already a same team name when student8 want to create a team. The second piece of code is from teams_controller_test.rb. It tests if the team number decreases when instructor1 creates a new team for a course.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, several parameters are needed. Usually we use four parameters: First, the method we are requesting. Second, an hash of request parameters for the method. Third, an optional hash of session variables. Forth, an optional hash of flash values. If we do not want to pass in the optional hash, we can set it to nil as the first piece of code shows, or we can just leave it blank as the second piece of code shows.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not. &lt;br /&gt;
&lt;br /&gt;
==Result==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Future Works==&lt;br /&gt;
===student_team_controller===&lt;br /&gt;
''Please note that this bug was reported fixed in the newest version of master branch of expertiza, but the fix came too late''&lt;br /&gt;
&lt;br /&gt;
There are several error raised from ''leave'' method need to be fixed, as mentioned above. Future teams may need to add tests on it as soon as it fixed, since it is a crucial functionality of the student team. &lt;br /&gt;
&lt;br /&gt;
Also, methods that seems like not being used, such as &amp;lt;code&amp;gt;advertise&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;remove_advertisement&amp;lt;/code&amp;gt; may need to be double checked and see if they are redundant.&lt;br /&gt;
===teams_controller===&lt;br /&gt;
The method &amp;lt;code&amp;gt;create_teams_view&amp;lt;/code&amp;gt; does not be used at all. So it is safe to delete it.&lt;br /&gt;
&lt;br /&gt;
The method &amp;lt;code&amp;gt;create_teams&amp;lt;/code&amp;gt; calls the method &amp;lt;code&amp;gt;randomize_all_by_parent&amp;lt;/code&amp;gt;, which is not correct. The developer may want to fix these bugs. &lt;br /&gt;
&lt;br /&gt;
It's possible that we can write more testing cases if we improve the fixture.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Qjia2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1406_st&amp;diff=84177</id>
		<title>CSC/ECE 517 Spring 2014/oss E1406 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1406_st&amp;diff=84177"/>
		<updated>2014-03-31T20:25:07Z</updated>

		<summary type="html">&lt;p&gt;Qjia2: /* teams_controller */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1406: Improve tests &amp;amp; investigate regex warnings for team functionality=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Classes==&lt;br /&gt;
=== app/controllers/teams_controller.rb ===&lt;br /&gt;
 &lt;br /&gt;
teams_controller contains functionalities for team management for instructor/TA accounts. &lt;br /&gt;
Instructor/TA can:&lt;br /&gt;
* view current teams&lt;br /&gt;
* create new teams&lt;br /&gt;
* import/export teams&lt;br /&gt;
* delete all teams/delete specified team&lt;br /&gt;
* copy existing teams from a course down to an assignment(inherit)&lt;br /&gt;
* update team's information&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/student_team_controller.rb ===&lt;br /&gt;
The student_team_controller support team management for student account.&lt;br /&gt;
student can&lt;br /&gt;
* create team&lt;br /&gt;
* view current team (including team invitations received and sent)&lt;br /&gt;
* advertise for their team&lt;br /&gt;
* remove the advertise for their team&lt;br /&gt;
* leave the team&lt;br /&gt;
* &amp;lt;del&amp;gt;review members&amp;lt;/del&amp;gt; (removed)&lt;br /&gt;
&lt;br /&gt;
== Motivation ==&lt;br /&gt;
There were no functional tests written on the two controllers to detect bugs, as well as confirming they are functional by itself and after integration.&lt;br /&gt;
&lt;br /&gt;
Our goal is to add comprehensive functional tests and integration tests to the two controllers to provide a preferable test suite for the future developers. &lt;br /&gt;
&lt;br /&gt;
Also, as the classes are influenced by the changes from other, we are also responsible for fixing some of the bugs, refactoring the method names to a better ones, as well as reporting the bugs found in the testing process.&lt;br /&gt;
&lt;br /&gt;
== Tasks ==&lt;br /&gt;
Overall: contribute to the code coverage, ideally having overall coverage increase 2%&lt;br /&gt;
===student_team_controller===&lt;br /&gt;
* write tests&lt;br /&gt;
* def advertise_for_partners  # change to “advertise”&lt;br /&gt;
* def remove # change to “remove_advertisment”&lt;br /&gt;
* def review # remove this method&lt;br /&gt;
&lt;br /&gt;
===teams_controller===&lt;br /&gt;
*write tests&lt;br /&gt;
&lt;br /&gt;
== Deployment ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
To see the result of tests, run &lt;br /&gt;
 rake test TEST=test/functional/student_team_controller.rb&lt;br /&gt;
and &lt;br /&gt;
 rake test TEST=test/functional/teams_controller&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
&lt;br /&gt;
;Framework : Rails default test framework&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/testing.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Total Number of Tests : ??&lt;br /&gt;
&lt;br /&gt;
===Testing Scenarios===&lt;br /&gt;
====student_team_controller====&lt;br /&gt;
Most of the test case are straightforward. There are some of the test cases was commented out due to bug in the controller&lt;br /&gt;
===== View student team (GET #view) =====&lt;br /&gt;
===== Edit team (GET #edit) =====&lt;br /&gt;
===== Create team with valid name (POST #create) =====&lt;br /&gt;
===== Create team with name in use (POST #create) =====&lt;br /&gt;
===== Update valid team name (POST #update) =====&lt;br /&gt;
===== Update team name in use (POST #update) =====&lt;br /&gt;
===== Update with current team name (POST #update) =====&lt;br /&gt;
===== Advertise (GET #advertise) =====&lt;br /&gt;
''This is currently commented out in the committed code. It seems like the method is never called. It raises missing template error upon every call. ''&lt;br /&gt;
The &amp;lt;code&amp;gt;advertise&amp;lt;/code&amp;gt; method was previously named advertise_for_partners, but renamed due to ambiguity as there is another class with the same name. &lt;br /&gt;
&lt;br /&gt;
===== Remove advertisement (GET #remove_advertisement ) =====&lt;br /&gt;
The &amp;lt;code&amp;gt;remove_advertisement&amp;lt;/code&amp;gt; method was previously named remove, but renamed to avoid ambiguity&lt;br /&gt;
This method is never called as well, but it is functional as it do not require any template.&lt;br /&gt;
===== Leave student team (GET #leave) =====&lt;br /&gt;
''This is currently commented out in the committed code, because it will raise error every time when called.''&lt;br /&gt;
It seems like problem happens on &lt;br /&gt;
  line 96: other_members = TeamsUser.where( ['team_id = ?', params[:team_id]]).first&lt;br /&gt;
  line 97: if other_members.length == 0&lt;br /&gt;
This will raise error due to the calling length of other_members, which is a single object but not an array.&lt;br /&gt;
Also, the related record seems to be remain undeleted in the database.&lt;br /&gt;
&lt;br /&gt;
====teams_controller====&lt;br /&gt;
Current test cases are as following.&lt;br /&gt;
=====Create team with valid name=====&lt;br /&gt;
=====Create team with existing name=====&lt;br /&gt;
=====Delete all teams=====&lt;br /&gt;
=====Delete specified team=====&lt;br /&gt;
=====Update team with valid name=====&lt;br /&gt;
=====Update team with existing name=====&lt;br /&gt;
=====List available teams=====&lt;br /&gt;
=====Inherit team from course to assignment=====&lt;br /&gt;
=====Create/Delete/Update/Inherit should redirect=====&lt;br /&gt;
The methods in the following are ignored in testing since they are never used in current codes.&lt;br /&gt;
=====create_teams_view=====&lt;br /&gt;
=====create_teams=====&lt;br /&gt;
&lt;br /&gt;
==Future Works==&lt;br /&gt;
===student_team_controller===&lt;br /&gt;
''Please note that this bug was reported fixed in the newest version of master branch of expertiza, but the fix came too late''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;There are several error raised from ''leave'' method need to be fixed, as mentioned above.&amp;lt;/del&amp;gt; Future teams may need to add tests on it as soon as it fixed, since it is a crucial functionality of the student team. &lt;br /&gt;
&lt;br /&gt;
Also, methods that seems like not being used, such as &amp;lt;code&amp;gt;advertise&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;remove_advertisement&amp;lt;/code&amp;gt; may need to be double checked and see if they are redundant.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Qjia2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1406_st&amp;diff=84176</id>
		<title>CSC/ECE 517 Spring 2014/oss E1406 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1406_st&amp;diff=84176"/>
		<updated>2014-03-31T20:20:57Z</updated>

		<summary type="html">&lt;p&gt;Qjia2: /* Tasks */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1406: Improve tests &amp;amp; investigate regex warnings for team functionality=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Classes==&lt;br /&gt;
=== app/controllers/teams_controller.rb ===&lt;br /&gt;
 &lt;br /&gt;
teams_controller contains functionalities for team management for instructor/TA accounts. &lt;br /&gt;
Instructor/TA can:&lt;br /&gt;
* view current teams&lt;br /&gt;
* create new teams&lt;br /&gt;
* import/export teams&lt;br /&gt;
* delete all teams/delete specified team&lt;br /&gt;
* copy existing teams from a course down to an assignment(inherit)&lt;br /&gt;
* update team's information&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/student_team_controller.rb ===&lt;br /&gt;
The student_team_controller support team management for student account.&lt;br /&gt;
student can&lt;br /&gt;
* create team&lt;br /&gt;
* view current team (including team invitations received and sent)&lt;br /&gt;
* advertise for their team&lt;br /&gt;
* remove the advertise for their team&lt;br /&gt;
* leave the team&lt;br /&gt;
* &amp;lt;del&amp;gt;review members&amp;lt;/del&amp;gt; (removed)&lt;br /&gt;
&lt;br /&gt;
== Motivation ==&lt;br /&gt;
There were no functional tests written on the two controllers to detect bugs, as well as confirming they are functional by itself and after integration.&lt;br /&gt;
&lt;br /&gt;
Our goal is to add comprehensive functional tests and integration tests to the two controllers to provide a preferable test suite for the future developers. &lt;br /&gt;
&lt;br /&gt;
Also, as the classes are influenced by the changes from other, we are also responsible for fixing some of the bugs, refactoring the method names to a better ones, as well as reporting the bugs found in the testing process.&lt;br /&gt;
&lt;br /&gt;
== Tasks ==&lt;br /&gt;
Overall: contribute to the code coverage, ideally having overall coverage increase 2%&lt;br /&gt;
===student_team_controller===&lt;br /&gt;
* write tests&lt;br /&gt;
* def advertise_for_partners  # change to “advertise”&lt;br /&gt;
* def remove # change to “remove_advertisment”&lt;br /&gt;
* def review # remove this method&lt;br /&gt;
&lt;br /&gt;
===teams_controller===&lt;br /&gt;
*write tests&lt;br /&gt;
&lt;br /&gt;
== Deployment ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
To see the result of tests, run &lt;br /&gt;
 rake test TEST=test/functional/student_team_controller.rb&lt;br /&gt;
and &lt;br /&gt;
 rake test TEST=test/functional/teams_controller&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
&lt;br /&gt;
;Framework : Rails default test framework&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/testing.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Total Number of Tests : ??&lt;br /&gt;
&lt;br /&gt;
===Testing Scenarios===&lt;br /&gt;
====student_team_controller====&lt;br /&gt;
Most of the test case are straightforward. There are some of the test cases was commented out due to bug in the controller&lt;br /&gt;
===== View student team (GET #view) =====&lt;br /&gt;
===== Edit team (GET #edit) =====&lt;br /&gt;
===== Create team with valid name (POST #create) =====&lt;br /&gt;
===== Create team with name in use (POST #create) =====&lt;br /&gt;
===== Update valid team name (POST #update) =====&lt;br /&gt;
===== Update team name in use (POST #update) =====&lt;br /&gt;
===== Update with current team name (POST #update) =====&lt;br /&gt;
===== Advertise (GET #advertise) =====&lt;br /&gt;
''This is currently commented out in the committed code. It seems like the method is never called. It raises missing template error upon every call. ''&lt;br /&gt;
The &amp;lt;code&amp;gt;advertise&amp;lt;/code&amp;gt; method was previously named advertise_for_partners, but renamed due to ambiguity as there is another class with the same name. &lt;br /&gt;
&lt;br /&gt;
===== Remove advertisement (GET #remove_advertisement ) =====&lt;br /&gt;
The &amp;lt;code&amp;gt;remove_advertisement&amp;lt;/code&amp;gt; method was previously named remove, but renamed to avoid ambiguity&lt;br /&gt;
This method is never called as well, but it is functional as it do not require any template.&lt;br /&gt;
===== Leave student team (GET #leave) =====&lt;br /&gt;
''This is currently commented out in the committed code, because it will raise error every time when called.''&lt;br /&gt;
It seems like problem happens on &lt;br /&gt;
  line 96: other_members = TeamsUser.where( ['team_id = ?', params[:team_id]]).first&lt;br /&gt;
  line 97: if other_members.length == 0&lt;br /&gt;
This will raise error due to the calling length of other_members, which is a single object but not an array.&lt;br /&gt;
Also, the related record seems to be remain undeleted in the database.&lt;br /&gt;
&lt;br /&gt;
====teams_controller====&lt;br /&gt;
Current test cases are as following. The method create_team_view is ignored in testing since in current codes it is never used&lt;br /&gt;
=====Create team with valid name=====&lt;br /&gt;
=====Create team with existing name=====&lt;br /&gt;
=====Delete all teams=====&lt;br /&gt;
=====Delete specified team=====&lt;br /&gt;
=====Update team with valid name=====&lt;br /&gt;
=====Update team with existing name=====&lt;br /&gt;
=====Inherit team from course to assignment=====&lt;br /&gt;
&lt;br /&gt;
==Future Works==&lt;br /&gt;
===student_team_controller===&lt;br /&gt;
''Please note that this bug was reported fixed in the newest version of master branch of expertiza, but the fix came too late''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;There are several error raised from ''leave'' method need to be fixed, as mentioned above.&amp;lt;/del&amp;gt; Future teams may need to add tests on it as soon as it fixed, since it is a crucial functionality of the student team. &lt;br /&gt;
&lt;br /&gt;
Also, methods that seems like not being used, such as &amp;lt;code&amp;gt;advertise&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;remove_advertisement&amp;lt;/code&amp;gt; may need to be double checked and see if they are redundant.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Qjia2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1406_st&amp;diff=84174</id>
		<title>CSC/ECE 517 Spring 2014/oss E1406 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1406_st&amp;diff=84174"/>
		<updated>2014-03-31T19:44:56Z</updated>

		<summary type="html">&lt;p&gt;Qjia2: /* teams_controller */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1406: Improve tests &amp;amp; investigate regex warnings for team functionality=&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Classes==&lt;br /&gt;
=== app/controllers/teams_controller.rb ===&lt;br /&gt;
 &lt;br /&gt;
teams_controller contains functionalities for team management for instructor/TA accounts. &lt;br /&gt;
Instructor/TA can:&lt;br /&gt;
* view current teams&lt;br /&gt;
* create new teams&lt;br /&gt;
* import/export teams&lt;br /&gt;
* delete all teams/delete specified team&lt;br /&gt;
* copy existing teams from a course down to an assignment(inherit)&lt;br /&gt;
* update team's information&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/student_team_controller.rb ===&lt;br /&gt;
The student_team_controller support team management for student account.&lt;br /&gt;
student can&lt;br /&gt;
* create team&lt;br /&gt;
* view current team (including team invitations received and sent)&lt;br /&gt;
* advertise for their team&lt;br /&gt;
* remove the advertise for their team&lt;br /&gt;
* leave the team&lt;br /&gt;
* &amp;lt;del&amp;gt;review members&amp;lt;/del&amp;gt; (removed)&lt;br /&gt;
&lt;br /&gt;
== Motivation ==&lt;br /&gt;
There were no functional tests written on the two controllers to detect bugs, as well as confirming they are functional by itself and after integration.&lt;br /&gt;
&lt;br /&gt;
Our goal is to add comprehensive functional tests and integration tests to the two controllers to provide a preferable test suite for the future developers. &lt;br /&gt;
&lt;br /&gt;
Also, as the classes are influenced by the changes from other, we are also responsible for fixing some of the bugs, refactoring the method names to a better ones, as well as reporting the bugs found in the testing process.&lt;br /&gt;
&lt;br /&gt;
== Tasks ==&lt;br /&gt;
Overall: contribute to the code coverage, ideally having overall coverage of 22%.&lt;br /&gt;
===student_team_controller===&lt;br /&gt;
* write tests&lt;br /&gt;
* def advertise_for_partners  # change to “advertise”&lt;br /&gt;
* def remove # change to “remove_advertisment”&lt;br /&gt;
* def review # remove this method&lt;br /&gt;
&lt;br /&gt;
===teams_controller===&lt;br /&gt;
*write tests&lt;br /&gt;
&lt;br /&gt;
== Deployment ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
To see the result of tests, run &lt;br /&gt;
 rake test TEST=test/functional/student_team_controller.rb&lt;br /&gt;
and &lt;br /&gt;
 rake test TEST=test/functional/teams_controller&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
&lt;br /&gt;
;Framework : Rails default test framework&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/testing.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Total Number of Tests : ??&lt;br /&gt;
&lt;br /&gt;
===Testing Scenarios===&lt;br /&gt;
====student_team_controller====&lt;br /&gt;
Most of the test case are straightforward. There are some of the test cases was commented out due to bug in the controller&lt;br /&gt;
===== View student team (GET #view) =====&lt;br /&gt;
===== Edit team (GET #edit) =====&lt;br /&gt;
===== Create team with valid name (POST #create) =====&lt;br /&gt;
===== Create team with name in use (POST #create) =====&lt;br /&gt;
===== Update valid team name (POST #update) =====&lt;br /&gt;
===== Update team name in use (POST #update) =====&lt;br /&gt;
===== Update with current team name (POST #update) =====&lt;br /&gt;
===== Advertise (GET #advertise) =====&lt;br /&gt;
''This is currently commented out in the committed code. It seems like the method is never called. It raises missing template error upon every call. ''&lt;br /&gt;
The &amp;lt;code&amp;gt;advertise&amp;lt;/code&amp;gt; method was previously named advertise_for_partners, but renamed due to ambiguity as there is another class with the same name. &lt;br /&gt;
&lt;br /&gt;
===== Remove advertisement (GET #remove_advertisement ) =====&lt;br /&gt;
The &amp;lt;code&amp;gt;remove_advertisement&amp;lt;/code&amp;gt; method was previously named remove, but renamed to avoid ambiguity&lt;br /&gt;
This method is never called as well, but it is functional as it do not require any template.&lt;br /&gt;
===== Leave student team (GET #leave) =====&lt;br /&gt;
''This is currently commented out in the committed code, because it will raise error every time when called.''&lt;br /&gt;
It seems like problem happens on &lt;br /&gt;
  line 96: other_members = TeamsUser.where( ['team_id = ?', params[:team_id]]).first&lt;br /&gt;
  line 97: if other_members.length == 0&lt;br /&gt;
This will raise error due to the calling length of other_members, which is a single object but not an array.&lt;br /&gt;
Also, the related record seems to be remain undeleted in the database.&lt;br /&gt;
&lt;br /&gt;
====teams_controller====&lt;br /&gt;
Current test cases are as following. The method create_team_view is ignored in testing since in current codes it is never used&lt;br /&gt;
=====Create team with valid name=====&lt;br /&gt;
=====Create team with existing name=====&lt;br /&gt;
=====Delete all teams=====&lt;br /&gt;
=====Delete specified team=====&lt;br /&gt;
=====Update team with valid name=====&lt;br /&gt;
=====Update team with existing name=====&lt;br /&gt;
=====Inherit team from course to assignment=====&lt;br /&gt;
&lt;br /&gt;
==Future Works==&lt;br /&gt;
===student_team_controller===&lt;br /&gt;
''Please note that this bug was reported fixed in the newest version of master branch of expertiza, but the fix came too late''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;There are several error raised from ''leave'' method need to be fixed, as mentioned above.&amp;lt;/del&amp;gt; Future teams may need to add tests on it as soon as it fixed, since it is a crucial functionality of the student team. &lt;br /&gt;
&lt;br /&gt;
Also, methods that seems like not being used, such as &amp;lt;code&amp;gt;advertise&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;remove_advertisement&amp;lt;/code&amp;gt; may need to be double checked and see if they are redundant.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Qjia2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1406_st&amp;diff=84172</id>
		<title>CSC/ECE 517 Spring 2014/oss E1406 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1406_st&amp;diff=84172"/>
		<updated>2014-03-31T19:43:01Z</updated>

		<summary type="html">&lt;p&gt;Qjia2: /* teams_controller */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1406: Improve tests &amp;amp; investigate regex warnings for team functionality=&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Classes==&lt;br /&gt;
=== app/controllers/teams_controller.rb ===&lt;br /&gt;
 &lt;br /&gt;
teams_controller contains functionalities for team management for instructor/TA accounts. &lt;br /&gt;
Instructor/TA can:&lt;br /&gt;
* view current teams&lt;br /&gt;
* create new teams&lt;br /&gt;
* import/export teams&lt;br /&gt;
* delete all teams/delete specified team&lt;br /&gt;
* copy existing teams from a course down to an assignment(inherit)&lt;br /&gt;
* update team's information&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/student_team_controller.rb ===&lt;br /&gt;
The student_team_controller support team management for student account.&lt;br /&gt;
student can&lt;br /&gt;
* create team&lt;br /&gt;
* view current team (including team invitations received and sent)&lt;br /&gt;
* advertise for their team&lt;br /&gt;
* remove the advertise for their team&lt;br /&gt;
* leave the team&lt;br /&gt;
* &amp;lt;del&amp;gt;review members&amp;lt;/del&amp;gt; (removed)&lt;br /&gt;
&lt;br /&gt;
== Motivation ==&lt;br /&gt;
There were no functional tests written on the two controllers to detect bugs, as well as confirming they are functional by itself and after integration.&lt;br /&gt;
&lt;br /&gt;
Our goal is to add comprehensive functional tests and integration tests to the two controllers to provide a preferable test suite for the future developers. &lt;br /&gt;
&lt;br /&gt;
Also, as the classes are influenced by the changes from other, we are also responsible for fixing some of the bugs, refactoring the method names to a better ones, as well as reporting the bugs found in the testing process.&lt;br /&gt;
&lt;br /&gt;
== Tasks ==&lt;br /&gt;
Overall: contribute to the code coverage, ideally having overall coverage of 22%.&lt;br /&gt;
===student_team_controller===&lt;br /&gt;
* write tests&lt;br /&gt;
* def advertise_for_partners  # change to “advertise”&lt;br /&gt;
* def remove # change to “remove_advertisment”&lt;br /&gt;
* def review # remove this method&lt;br /&gt;
&lt;br /&gt;
===teams_controller===&lt;br /&gt;
*write tests&lt;br /&gt;
*ignore create_teams_view method since it is not used&lt;br /&gt;
&lt;br /&gt;
== Deployment ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
To see the result of tests, run &lt;br /&gt;
 rake test TEST=test/functional/student_team_controller.rb&lt;br /&gt;
and &lt;br /&gt;
 rake test TEST=test/functional/teams_controller&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
&lt;br /&gt;
;Framework : Rails default test framework&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/testing.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Total Number of Tests : ??&lt;br /&gt;
&lt;br /&gt;
===Testing Scenarios===&lt;br /&gt;
====student_team_controller====&lt;br /&gt;
Most of the test case are straightforward. There are some of the test cases was commented out due to bug in the controller&lt;br /&gt;
===== View student team (GET #view) =====&lt;br /&gt;
===== Edit team (GET #edit) =====&lt;br /&gt;
===== Create team with valid name (POST #create) =====&lt;br /&gt;
===== Create team with name in use (POST #create) =====&lt;br /&gt;
===== Update valid team name (POST #update) =====&lt;br /&gt;
===== Update team name in use (POST #update) =====&lt;br /&gt;
===== Update with current team name (POST #update) =====&lt;br /&gt;
===== Advertise (GET #advertise) =====&lt;br /&gt;
''This is currently commented out in the committed code. It seems like the method is never called. It raises missing template error upon every call. ''&lt;br /&gt;
The &amp;lt;code&amp;gt;advertise&amp;lt;/code&amp;gt; method was previously named advertise_for_partners, but renamed due to ambiguity as there is another class with the same name. &lt;br /&gt;
&lt;br /&gt;
===== Remove advertisement (GET #remove_advertisement ) =====&lt;br /&gt;
The &amp;lt;code&amp;gt;remove_advertisement&amp;lt;/code&amp;gt; method was previously named remove, but renamed to avoid ambiguity&lt;br /&gt;
This method is never called as well, but it is functional as it do not require any template.&lt;br /&gt;
===== Leave student team (GET #leave) =====&lt;br /&gt;
''This is currently commented out in the committed code, because it will raise error every time when called.''&lt;br /&gt;
It seems like problem happens on &lt;br /&gt;
  line 96: other_members = TeamsUser.where( ['team_id = ?', params[:team_id]]).first&lt;br /&gt;
  line 97: if other_members.length == 0&lt;br /&gt;
This will raise error due to the calling length of other_members, which is a single object but not an array.&lt;br /&gt;
Also, the related record seems to be remain undeleted in the database.&lt;br /&gt;
&lt;br /&gt;
====teams_controller====&lt;br /&gt;
Current test cases are as following. The method create_team_view is ignored in testing since in current codes it is never used&lt;br /&gt;
=====Create team with valid name=====&lt;br /&gt;
=====Create team with existing name=====&lt;br /&gt;
=====Delete all teams=====&lt;br /&gt;
=====Delete specified team=====&lt;br /&gt;
=====Update team with valid name=====&lt;br /&gt;
=====Update team with existing name=====&lt;br /&gt;
=====Inherit team from course to assignment=====&lt;br /&gt;
&lt;br /&gt;
==Future Works==&lt;br /&gt;
===student_team_controller===&lt;br /&gt;
''Please note that this bug was reported fixed in the newest version of master branch of expertiza, but the fix came too late''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;There are several error raised from ''leave'' method need to be fixed, as mentioned above.&amp;lt;/del&amp;gt; Future teams may need to add tests on it as soon as it fixed, since it is a crucial functionality of the student team. &lt;br /&gt;
&lt;br /&gt;
Also, methods that seems like not being used, such as &amp;lt;code&amp;gt;advertise&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;remove_advertisement&amp;lt;/code&amp;gt; may need to be double checked and see if they are redundant.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Qjia2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1406_st&amp;diff=84169</id>
		<title>CSC/ECE 517 Spring 2014/oss E1406 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1406_st&amp;diff=84169"/>
		<updated>2014-03-31T19:42:10Z</updated>

		<summary type="html">&lt;p&gt;Qjia2: /* Testing Scenarios */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1406: Improve tests &amp;amp; investigate regex warnings for team functionality=&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Classes==&lt;br /&gt;
=== app/controllers/teams_controller.rb ===&lt;br /&gt;
 &lt;br /&gt;
teams_controller contains functionalities for team management for instructor/TA accounts. &lt;br /&gt;
Instructor/TA can:&lt;br /&gt;
* view current teams&lt;br /&gt;
* create new teams&lt;br /&gt;
* import/export teams&lt;br /&gt;
* delete all teams/delete specified team&lt;br /&gt;
* copy existing teams from a course down to an assignment(inherit)&lt;br /&gt;
* update team's information&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/student_team_controller.rb ===&lt;br /&gt;
The student_team_controller support team management for student account.&lt;br /&gt;
student can&lt;br /&gt;
* create team&lt;br /&gt;
* view current team (including team invitations received and sent)&lt;br /&gt;
* advertise for their team&lt;br /&gt;
* remove the advertise for their team&lt;br /&gt;
* leave the team&lt;br /&gt;
* &amp;lt;del&amp;gt;review members&amp;lt;/del&amp;gt; (removed)&lt;br /&gt;
&lt;br /&gt;
== Motivation ==&lt;br /&gt;
There were no functional tests written on the two controllers to detect bugs, as well as confirming they are functional by itself and after integration.&lt;br /&gt;
&lt;br /&gt;
Our goal is to add comprehensive functional tests and integration tests to the two controllers to provide a preferable test suite for the future developers. &lt;br /&gt;
&lt;br /&gt;
Also, as the classes are influenced by the changes from other, we are also responsible for fixing some of the bugs, refactoring the method names to a better ones, as well as reporting the bugs found in the testing process.&lt;br /&gt;
&lt;br /&gt;
== Tasks ==&lt;br /&gt;
Overall: contribute to the code coverage, ideally having overall coverage of 22%.&lt;br /&gt;
===student_team_controller===&lt;br /&gt;
* write tests&lt;br /&gt;
* def advertise_for_partners  # change to “advertise”&lt;br /&gt;
* def remove # change to “remove_advertisment”&lt;br /&gt;
* def review # remove this method&lt;br /&gt;
&lt;br /&gt;
===teams_controller===&lt;br /&gt;
*write tests&lt;br /&gt;
*ignore create_teams_view method since it is not used&lt;br /&gt;
&lt;br /&gt;
== Deployment ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
To see the result of tests, run &lt;br /&gt;
 rake test TEST=test/functional/student_team_controller.rb&lt;br /&gt;
and &lt;br /&gt;
 rake test TEST=test/functional/teams_controller&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
&lt;br /&gt;
;Framework : Rails default test framework&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/testing.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Total Number of Tests : ??&lt;br /&gt;
&lt;br /&gt;
===Testing Scenarios===&lt;br /&gt;
====student_team_controller====&lt;br /&gt;
Most of the test case are straightforward. There are some of the test cases was commented out due to bug in the controller&lt;br /&gt;
===== View student team (GET #view) =====&lt;br /&gt;
===== Edit team (GET #edit) =====&lt;br /&gt;
===== Create team with valid name (POST #create) =====&lt;br /&gt;
===== Create team with name in use (POST #create) =====&lt;br /&gt;
===== Update valid team name (POST #update) =====&lt;br /&gt;
===== Update team name in use (POST #update) =====&lt;br /&gt;
===== Update with current team name (POST #update) =====&lt;br /&gt;
===== Advertise (GET #advertise) =====&lt;br /&gt;
''This is currently commented out in the committed code. It seems like the method is never called. It raises missing template error upon every call. ''&lt;br /&gt;
The &amp;lt;code&amp;gt;advertise&amp;lt;/code&amp;gt; method was previously named advertise_for_partners, but renamed due to ambiguity as there is another class with the same name. &lt;br /&gt;
&lt;br /&gt;
===== Remove advertisement (GET #remove_advertisement ) =====&lt;br /&gt;
The &amp;lt;code&amp;gt;remove_advertisement&amp;lt;/code&amp;gt; method was previously named remove, but renamed to avoid ambiguity&lt;br /&gt;
This method is never called as well, but it is functional as it do not require any template.&lt;br /&gt;
===== Leave student team (GET #leave) =====&lt;br /&gt;
''This is currently commented out in the committed code, because it will raise error every time when called.''&lt;br /&gt;
It seems like problem happens on &lt;br /&gt;
  line 96: other_members = TeamsUser.where( ['team_id = ?', params[:team_id]]).first&lt;br /&gt;
  line 97: if other_members.length == 0&lt;br /&gt;
This will raise error due to the calling length of other_members, which is a single object but not an array.&lt;br /&gt;
Also, the related record seems to be remain undeleted in the database.&lt;br /&gt;
&lt;br /&gt;
====teams_controller====&lt;br /&gt;
The method create_team_view is ignored in testing since in current codes it is never used&lt;br /&gt;
=====Create team with valid name=====&lt;br /&gt;
=====Create team with existing name=====&lt;br /&gt;
=====Delete all teams=====&lt;br /&gt;
=====Delete specified team=====&lt;br /&gt;
=====Update team with valid name=====&lt;br /&gt;
=====Update team with existing name=====&lt;br /&gt;
=====Inherit team from course to assignment=====&lt;br /&gt;
&lt;br /&gt;
==Future Works==&lt;br /&gt;
===student_team_controller===&lt;br /&gt;
''Please note that this bug was reported fixed in the newest version of master branch of expertiza, but the fix came too late''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;There are several error raised from ''leave'' method need to be fixed, as mentioned above.&amp;lt;/del&amp;gt; Future teams may need to add tests on it as soon as it fixed, since it is a crucial functionality of the student team. &lt;br /&gt;
&lt;br /&gt;
Also, methods that seems like not being used, such as &amp;lt;code&amp;gt;advertise&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;remove_advertisement&amp;lt;/code&amp;gt; may need to be double checked and see if they are redundant.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Qjia2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1406_st&amp;diff=84164</id>
		<title>CSC/ECE 517 Spring 2014/oss E1406 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1406_st&amp;diff=84164"/>
		<updated>2014-03-31T19:33:04Z</updated>

		<summary type="html">&lt;p&gt;Qjia2: /* student_team_controller */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1406: Improve tests &amp;amp; investigate regex warnings for team functionality=&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Classes==&lt;br /&gt;
=== app/controllers/teams_controller.rb ===&lt;br /&gt;
 &lt;br /&gt;
teams_controller contains functionalities for team management for instructor/TA accounts. &lt;br /&gt;
Instructor/TA can:&lt;br /&gt;
* view current teams&lt;br /&gt;
* create new teams&lt;br /&gt;
* import/export teams&lt;br /&gt;
* delete all teams/delete specified team&lt;br /&gt;
* copy existing teams from a course down to an assignment(inherit)&lt;br /&gt;
* update team's information&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/student_team_controller.rb ===&lt;br /&gt;
The student_team_controller support team management for student account.&lt;br /&gt;
student can&lt;br /&gt;
* create team&lt;br /&gt;
* view current team (including team invitations received and sent)&lt;br /&gt;
* advertise for their team&lt;br /&gt;
* remove the advertise for their team&lt;br /&gt;
* leave the team&lt;br /&gt;
* &amp;lt;del&amp;gt;review members&amp;lt;/del&amp;gt; (removed)&lt;br /&gt;
&lt;br /&gt;
== Motivation ==&lt;br /&gt;
There were no functional tests written on the two controllers to detect bugs, as well as confirming they are functional by itself and after integration.&lt;br /&gt;
&lt;br /&gt;
Our goal is to add comprehensive functional tests and integration tests to the two controllers to provide a preferable test suite for the future developers. &lt;br /&gt;
&lt;br /&gt;
Also, as the classes are influenced by the changes from other, we are also responsible for fixing some of the bugs, refactoring the method names to a better ones, as well as reporting the bugs found in the testing process.&lt;br /&gt;
&lt;br /&gt;
== Tasks ==&lt;br /&gt;
Overall: contribute to the code coverage, ideally having overall coverage of 22%.&lt;br /&gt;
===student_team_controller===&lt;br /&gt;
* write tests&lt;br /&gt;
* def advertise_for_partners  # change to “advertise”&lt;br /&gt;
* def remove # change to “remove_advertisment”&lt;br /&gt;
* def review # remove this method&lt;br /&gt;
&lt;br /&gt;
===teams_controller===&lt;br /&gt;
*write tests&lt;br /&gt;
*ignore create_teams_view method since it is not used&lt;br /&gt;
&lt;br /&gt;
== Deployment ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
To see the result of tests, run &lt;br /&gt;
 rake test TEST=test/functional/student_team_controller.rb&lt;br /&gt;
and &lt;br /&gt;
 rake test TEST=test/functional/teams_controller&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
&lt;br /&gt;
;Framework : Rails default test framework&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/testing.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Total Number of Tests : ??&lt;br /&gt;
&lt;br /&gt;
===Testing Scenarios===&lt;br /&gt;
====student_team_controller====&lt;br /&gt;
Most of the test case are straightforward. There are some of the test cases was commented out due to bug in the controller&lt;br /&gt;
===== View student team (GET #view) =====&lt;br /&gt;
===== Edit team (GET #edit) =====&lt;br /&gt;
===== Create team with valid name (POST #create) =====&lt;br /&gt;
===== Create team with name in use (POST #create) =====&lt;br /&gt;
===== Update valid team name (POST #update) =====&lt;br /&gt;
===== Update team name in use (POST #update) =====&lt;br /&gt;
===== Update with current team name (POST #update) =====&lt;br /&gt;
===== Advertise (GET #advertise) =====&lt;br /&gt;
''This is currently commented out in the committed code. It seems like the method is never called. It raises missing template error upon every call. ''&lt;br /&gt;
The &amp;lt;code&amp;gt;advertise&amp;lt;/code&amp;gt; method was previously named advertise_for_partners, but renamed due to ambiguity as there is another class with the same name. &lt;br /&gt;
&lt;br /&gt;
===== Remove advertisement (GET #remove_advertisement ) =====&lt;br /&gt;
The &amp;lt;code&amp;gt;remove_advertisement&amp;lt;/code&amp;gt; method was previously named remove, but renamed to avoid ambiguity&lt;br /&gt;
This method is never called as well, but it is functional as it do not require any template.&lt;br /&gt;
===== Leave student team (GET #leave) =====&lt;br /&gt;
''This is currently commented out in the committed code, because it will raise error every time when called.''&lt;br /&gt;
It seems like problem happens on &lt;br /&gt;
  line 96: other_members = TeamsUser.where( ['team_id = ?', params[:team_id]]).first&lt;br /&gt;
  line 97: if other_members.length == 0&lt;br /&gt;
This will raise error due to the calling length of other_members, which is a single object but not an array.&lt;br /&gt;
Also, the related record seems to be remain undeleted in the database.&lt;br /&gt;
&lt;br /&gt;
==Future Works==&lt;br /&gt;
===student_team_controller===&lt;br /&gt;
''Please note that this bug was reported fixed in the newest version of master branch of expertiza, but the fix came too late''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;There are several error raised from ''leave'' method need to be fixed, as mentioned above.&amp;lt;/del&amp;gt; Future teams may need to add tests on it as soon as it fixed, since it is a crucial functionality of the student team. &lt;br /&gt;
&lt;br /&gt;
Also, methods that seems like not being used, such as &amp;lt;code&amp;gt;advertise&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;remove_advertisement&amp;lt;/code&amp;gt; may need to be double checked and see if they are redundant.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Qjia2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1406_st&amp;diff=84162</id>
		<title>CSC/ECE 517 Spring 2014/oss E1406 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1406_st&amp;diff=84162"/>
		<updated>2014-03-31T19:28:41Z</updated>

		<summary type="html">&lt;p&gt;Qjia2: /* app/controllers/teams_controller.rb */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1406: Improve tests &amp;amp; investigate regex warnings for team functionality=&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Classes==&lt;br /&gt;
=== app/controllers/teams_controller.rb ===&lt;br /&gt;
 &lt;br /&gt;
teams_controller contains functionalities for team management for instructor/TA accounts. &lt;br /&gt;
Instructor/TA can:&lt;br /&gt;
* view current teams&lt;br /&gt;
* create new teams&lt;br /&gt;
* import/export teams&lt;br /&gt;
* delete all teams/delete specified team&lt;br /&gt;
* copy existing teams from a course down to an assignment(inherit)&lt;br /&gt;
* update team's information&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/student_team_controller.rb ===&lt;br /&gt;
The student_team_controller support team management for student account.&lt;br /&gt;
student can&lt;br /&gt;
* create team&lt;br /&gt;
* view current team (including team invitations received and sent)&lt;br /&gt;
* advertise for their team&lt;br /&gt;
* remove the advertise for their team&lt;br /&gt;
* leave the team&lt;br /&gt;
* &amp;lt;del&amp;gt;review members&amp;lt;/del&amp;gt; (removed)&lt;br /&gt;
&lt;br /&gt;
== Motivation ==&lt;br /&gt;
There were no functional tests written on the two controllers to detect bugs, as well as confirming they are functional by itself and after integration.&lt;br /&gt;
&lt;br /&gt;
Our goal is to add comprehensive functional tests and integration tests to the two controllers to provide a preferable test suite for the future developers. &lt;br /&gt;
&lt;br /&gt;
Also, as the classes are influenced by the changes from other, we are also responsible for fixing some of the bugs, refactoring the method names to a better ones, as well as reporting the bugs found in the testing process.&lt;br /&gt;
&lt;br /&gt;
== Tasks ==&lt;br /&gt;
Overall: contribute to the code coverage, ideally having overall coverage of 22%.&lt;br /&gt;
===student_team_controller===&lt;br /&gt;
* write tests&lt;br /&gt;
* def advertise_for_partners  # change to “advertise”&lt;br /&gt;
* def remove # change to “remove_advertisment”&lt;br /&gt;
* def review # remove this method&lt;br /&gt;
&lt;br /&gt;
== Deployment ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
To see the result of tests, run &lt;br /&gt;
 rake test TEST=test/functional/student_team_controller.rb&lt;br /&gt;
and &lt;br /&gt;
 rake test TEST=test/functional/teams_controller&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
&lt;br /&gt;
;Framework : Rails default test framework&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/testing.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Total Number of Tests : ??&lt;br /&gt;
&lt;br /&gt;
===Testing Scenarios===&lt;br /&gt;
====student_team_controller====&lt;br /&gt;
Most of the test case are straightforward. There are some of the test cases was commented out due to bug in the controller&lt;br /&gt;
===== View student team (GET #view) =====&lt;br /&gt;
===== Edit team (GET #edit) =====&lt;br /&gt;
===== Create team with valid name (POST #create) =====&lt;br /&gt;
===== Create team with name in use (POST #create) =====&lt;br /&gt;
===== Update valid team name (POST #update) =====&lt;br /&gt;
===== Update team name in use (POST #update) =====&lt;br /&gt;
===== Update with current team name (POST #update) =====&lt;br /&gt;
===== Advertise (GET #advertise) =====&lt;br /&gt;
''This is currently commented out in the committed code. It seems like the method is never called. It raises missing template error upon every call. ''&lt;br /&gt;
The &amp;lt;code&amp;gt;advertise&amp;lt;/code&amp;gt; method was previously named advertise_for_partners, but renamed due to ambiguity as there is another class with the same name. &lt;br /&gt;
&lt;br /&gt;
===== Remove advertisement (GET #remove_advertisement ) =====&lt;br /&gt;
The &amp;lt;code&amp;gt;remove_advertisement&amp;lt;/code&amp;gt; method was previously named remove, but renamed to avoid ambiguity&lt;br /&gt;
This method is never called as well, but it is functional as it do not require any template.&lt;br /&gt;
===== Leave student team (GET #leave) =====&lt;br /&gt;
''This is currently commented out in the committed code, because it will raise error every time when called.''&lt;br /&gt;
It seems like problem happens on &lt;br /&gt;
  line 96: other_members = TeamsUser.where( ['team_id = ?', params[:team_id]]).first&lt;br /&gt;
  line 97: if other_members.length == 0&lt;br /&gt;
This will raise error due to the calling length of other_members, which is a single object but not an array.&lt;br /&gt;
Also, the related record seems to be remain undeleted in the database.&lt;br /&gt;
&lt;br /&gt;
==Future Works==&lt;br /&gt;
===student_team_controller===&lt;br /&gt;
''Please note that this bug was reported fixed in the newest version of master branch of expertiza, but the fix came too late''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;There are several error raised from ''leave'' method need to be fixed, as mentioned above.&amp;lt;/del&amp;gt; Future teams may need to add tests on it as soon as it fixed, since it is a crucial functionality of the student team. &lt;br /&gt;
&lt;br /&gt;
Also, methods that seems like not being used, such as &amp;lt;code&amp;gt;advertise&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;remove_advertisement&amp;lt;/code&amp;gt; may need to be double checked and see if they are redundant.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Qjia2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1406_st&amp;diff=84161</id>
		<title>CSC/ECE 517 Spring 2014/oss E1406 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1406_st&amp;diff=84161"/>
		<updated>2014-03-31T19:25:52Z</updated>

		<summary type="html">&lt;p&gt;Qjia2: /* app/controllers/teams_controller.rb */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1406: Improve tests &amp;amp; investigate regex warnings for team functionality=&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Classes==&lt;br /&gt;
=== app/controllers/teams_controller.rb ===&lt;br /&gt;
 &lt;br /&gt;
teams_controller contains functionalities for team management for instructor/TA accounts. &lt;br /&gt;
Instructor/TA can:&lt;br /&gt;
* view current teams&lt;br /&gt;
* create new teams&lt;br /&gt;
* import/export teams&lt;br /&gt;
* delete all teams/delete specified team&lt;br /&gt;
* copy existing teams from a course down to an assignment(inherit)&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/student_team_controller.rb ===&lt;br /&gt;
The student_team_controller support team management for student account.&lt;br /&gt;
student can&lt;br /&gt;
* create team&lt;br /&gt;
* view current team (including team invitations received and sent)&lt;br /&gt;
* advertise for their team&lt;br /&gt;
* remove the advertise for their team&lt;br /&gt;
* leave the team&lt;br /&gt;
* &amp;lt;del&amp;gt;review members&amp;lt;/del&amp;gt; (removed)&lt;br /&gt;
&lt;br /&gt;
== Motivation ==&lt;br /&gt;
There were no functional tests written on the two controllers to detect bugs, as well as confirming they are functional by itself and after integration.&lt;br /&gt;
&lt;br /&gt;
Our goal is to add comprehensive functional tests and integration tests to the two controllers to provide a preferable test suite for the future developers. &lt;br /&gt;
&lt;br /&gt;
Also, as the classes are influenced by the changes from other, we are also responsible for fixing some of the bugs, refactoring the method names to a better ones, as well as reporting the bugs found in the testing process.&lt;br /&gt;
&lt;br /&gt;
== Tasks ==&lt;br /&gt;
Overall: contribute to the code coverage, ideally having overall coverage of 22%.&lt;br /&gt;
===student_team_controller===&lt;br /&gt;
* write tests&lt;br /&gt;
* def advertise_for_partners  # change to “advertise”&lt;br /&gt;
* def remove # change to “remove_advertisment”&lt;br /&gt;
* def review # remove this method&lt;br /&gt;
&lt;br /&gt;
== Deployment ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
To see the result of tests, run &lt;br /&gt;
 rake test TEST=test/functional/student_team_controller.rb&lt;br /&gt;
and &lt;br /&gt;
 rake test TEST=test/functional/teams_controller&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
&lt;br /&gt;
;Framework : Rails default test framework&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/testing.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Total Number of Tests : ??&lt;br /&gt;
&lt;br /&gt;
===Testing Scenarios===&lt;br /&gt;
====student_team_controller====&lt;br /&gt;
Most of the test case are straightforward. There are some of the test cases was commented out due to bug in the controller&lt;br /&gt;
===== View student team (GET #view) =====&lt;br /&gt;
===== Edit team (GET #edit) =====&lt;br /&gt;
===== Create team with valid name (POST #create) =====&lt;br /&gt;
===== Create team with name in use (POST #create) =====&lt;br /&gt;
===== Update valid team name (POST #update) =====&lt;br /&gt;
===== Update team name in use (POST #update) =====&lt;br /&gt;
===== Update with current team name (POST #update) =====&lt;br /&gt;
===== Advertise (GET #advertise) =====&lt;br /&gt;
''This is currently commented out in the committed code. It seems like the method is never called. It raises missing template error upon every call. ''&lt;br /&gt;
The &amp;lt;code&amp;gt;advertise&amp;lt;/code&amp;gt; method was previously named advertise_for_partners, but renamed due to ambiguity as there is another class with the same name. &lt;br /&gt;
&lt;br /&gt;
===== Remove advertisement (GET #remove_advertisement ) =====&lt;br /&gt;
The &amp;lt;code&amp;gt;remove_advertisement&amp;lt;/code&amp;gt; method was previously named remove, but renamed to avoid ambiguity&lt;br /&gt;
This method is never called as well, but it is functional as it do not require any template.&lt;br /&gt;
===== Leave student team (GET #leave) =====&lt;br /&gt;
''This is currently commented out in the committed code, because it will raise error every time when called.''&lt;br /&gt;
It seems like problem happens on &lt;br /&gt;
  line 96: other_members = TeamsUser.where( ['team_id = ?', params[:team_id]]).first&lt;br /&gt;
  line 97: if other_members.length == 0&lt;br /&gt;
This will raise error due to the calling length of other_members, which is a single object but not an array.&lt;br /&gt;
Also, the related record seems to be remain undeleted in the database.&lt;br /&gt;
&lt;br /&gt;
==Future Works==&lt;br /&gt;
===student_team_controller===&lt;br /&gt;
''Please note that this bug was reported fixed in the newest version of master branch of expertiza, but the fix came too late''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;There are several error raised from ''leave'' method need to be fixed, as mentioned above.&amp;lt;/del&amp;gt; Future teams may need to add tests on it as soon as it fixed, since it is a crucial functionality of the student team. &lt;br /&gt;
&lt;br /&gt;
Also, methods that seems like not being used, such as &amp;lt;code&amp;gt;advertise&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;remove_advertisement&amp;lt;/code&amp;gt; may need to be double checked and see if they are redundant.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Qjia2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1406_st&amp;diff=84160</id>
		<title>CSC/ECE 517 Spring 2014/oss E1406 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1406_st&amp;diff=84160"/>
		<updated>2014-03-31T19:25:23Z</updated>

		<summary type="html">&lt;p&gt;Qjia2: /* app/controllers/teams_controller.rb */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1406: Improve tests &amp;amp; investigate regex warnings for team functionality=&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Classes==&lt;br /&gt;
=== app/controllers/teams_controller.rb ===&lt;br /&gt;
 &lt;br /&gt;
teams_controller contains functionalities for team management for instructor/TA accounts. &lt;br /&gt;
Instructor/TA can:&lt;br /&gt;
* view current teams&lt;br /&gt;
* create new teams&lt;br /&gt;
* import/export teams&lt;br /&gt;
* delete all teams/delete specified team&lt;br /&gt;
* copy existing teams from a course down to an assignment&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/student_team_controller.rb ===&lt;br /&gt;
The student_team_controller support team management for student account.&lt;br /&gt;
student can&lt;br /&gt;
* create team&lt;br /&gt;
* view current team (including team invitations received and sent)&lt;br /&gt;
* advertise for their team&lt;br /&gt;
* remove the advertise for their team&lt;br /&gt;
* leave the team&lt;br /&gt;
* &amp;lt;del&amp;gt;review members&amp;lt;/del&amp;gt; (removed)&lt;br /&gt;
&lt;br /&gt;
== Motivation ==&lt;br /&gt;
There were no functional tests written on the two controllers to detect bugs, as well as confirming they are functional by itself and after integration.&lt;br /&gt;
&lt;br /&gt;
Our goal is to add comprehensive functional tests and integration tests to the two controllers to provide a preferable test suite for the future developers. &lt;br /&gt;
&lt;br /&gt;
Also, as the classes are influenced by the changes from other, we are also responsible for fixing some of the bugs, refactoring the method names to a better ones, as well as reporting the bugs found in the testing process.&lt;br /&gt;
&lt;br /&gt;
== Tasks ==&lt;br /&gt;
Overall: contribute to the code coverage, ideally having overall coverage of 22%.&lt;br /&gt;
===student_team_controller===&lt;br /&gt;
* write tests&lt;br /&gt;
* def advertise_for_partners  # change to “advertise”&lt;br /&gt;
* def remove # change to “remove_advertisment”&lt;br /&gt;
* def review # remove this method&lt;br /&gt;
&lt;br /&gt;
== Deployment ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
To see the result of tests, run &lt;br /&gt;
 rake test TEST=test/functional/student_team_controller.rb&lt;br /&gt;
and &lt;br /&gt;
 rake test TEST=test/functional/teams_controller&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
&lt;br /&gt;
;Framework : Rails default test framework&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/testing.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Total Number of Tests : ??&lt;br /&gt;
&lt;br /&gt;
===Testing Scenarios===&lt;br /&gt;
====student_team_controller====&lt;br /&gt;
Most of the test case are straightforward. There are some of the test cases was commented out due to bug in the controller&lt;br /&gt;
===== View student team (GET #view) =====&lt;br /&gt;
===== Edit team (GET #edit) =====&lt;br /&gt;
===== Create team with valid name (POST #create) =====&lt;br /&gt;
===== Create team with name in use (POST #create) =====&lt;br /&gt;
===== Update valid team name (POST #update) =====&lt;br /&gt;
===== Update team name in use (POST #update) =====&lt;br /&gt;
===== Update with current team name (POST #update) =====&lt;br /&gt;
===== Advertise (GET #advertise) =====&lt;br /&gt;
''This is currently commented out in the committed code. It seems like the method is never called. It raises missing template error upon every call. ''&lt;br /&gt;
The &amp;lt;code&amp;gt;advertise&amp;lt;/code&amp;gt; method was previously named advertise_for_partners, but renamed due to ambiguity as there is another class with the same name. &lt;br /&gt;
&lt;br /&gt;
===== Remove advertisement (GET #remove_advertisement ) =====&lt;br /&gt;
The &amp;lt;code&amp;gt;remove_advertisement&amp;lt;/code&amp;gt; method was previously named remove, but renamed to avoid ambiguity&lt;br /&gt;
This method is never called as well, but it is functional as it do not require any template.&lt;br /&gt;
===== Leave student team (GET #leave) =====&lt;br /&gt;
''This is currently commented out in the committed code, because it will raise error every time when called.''&lt;br /&gt;
It seems like problem happens on &lt;br /&gt;
  line 96: other_members = TeamsUser.where( ['team_id = ?', params[:team_id]]).first&lt;br /&gt;
  line 97: if other_members.length == 0&lt;br /&gt;
This will raise error due to the calling length of other_members, which is a single object but not an array.&lt;br /&gt;
Also, the related record seems to be remain undeleted in the database.&lt;br /&gt;
&lt;br /&gt;
==Future Works==&lt;br /&gt;
===student_team_controller===&lt;br /&gt;
''Please note that this bug was reported fixed in the newest version of master branch of expertiza, but the fix came too late''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;There are several error raised from ''leave'' method need to be fixed, as mentioned above.&amp;lt;/del&amp;gt; Future teams may need to add tests on it as soon as it fixed, since it is a crucial functionality of the student team. &lt;br /&gt;
&lt;br /&gt;
Also, methods that seems like not being used, such as &amp;lt;code&amp;gt;advertise&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;remove_advertisement&amp;lt;/code&amp;gt; may need to be double checked and see if they are redundant.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Qjia2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1h_jg&amp;diff=83147</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1h jg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1h_jg&amp;diff=83147"/>
		<updated>2014-02-10T21:20:07Z</updated>

		<summary type="html">&lt;p&gt;Qjia2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== '''Ruby libraries to load objects of other languages at run time''' ==&lt;br /&gt;
&lt;br /&gt;
This is an advanced topic. Libraries are being developed where Ruby gems can load libraries (and even native code) of other languages.A few open-source projects like FFI are currently working on this. Previous version is available [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/ch1_1w21_w here]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
==Introduction==&lt;br /&gt;
===Runtime Library===&lt;br /&gt;
In computer programming, a runtime library is the API used by a compiler to invoke some of the behaviors of a runtime system. The runtime system implements the execution model and other fundamental behaviors of a programming language. The compiler inserts calls to the runtime library into the executable binary. During execution (run time) of that computer program, execution of those calls to the runtime library cause communication between the application and the runtime system. This often includes functions for input and output, or for memory management.&lt;br /&gt;
The runtime library may implement a portion of the runtime system's behavior, but if one reads the code of the calls available, they typically are thin wrappers that simply package information and send it to the runtime system. However, sometimes the term runtime library is meant to include the code of the runtime system itself, even though much of that code cannot be directly reached via a library call.&lt;br /&gt;
&lt;br /&gt;
For example, some language features that can be performed only (or are more efficient or accurate) at runtime are implemented in the runtime system and may be invoked via the runtime library API, e.g. some logic errors, array bounds checking, dynamic type checking, exception handling and possibly debugging functionality. For this reason, some programming bugs are not discovered until the program is tested in a &amp;quot;live&amp;quot; environment with real data, despite sophisticated compile-time checking and pre-release testing. In this case, the end user may encounter a runtime error message.&lt;br /&gt;
&lt;br /&gt;
The concept of a runtime library should not be confused with an ordinary program library like that created by an application programmer or delivered by a third party, nor with a dynamic library, meaning a program library linked at run time.&lt;br /&gt;
&lt;br /&gt;
===libffi===&lt;br /&gt;
FFI stands for Foreign Function Interface. A foreign function interface is the popular name for the interface that allows code written in one language to call code written in another language. The libffi was originally written by Anthony Green&amp;lt;ref&amp;gt;http://moxielogic.org/blog&amp;lt;/ref&amp;gt;. The libffi library really only provides the lowest, machine dependent layer of a fully featured foreign function interface. A layer must exist above libffi that handles type conversions for values passed between the two languages.&amp;lt;ref&amp;gt;http://sourceware.org/libffi/&amp;lt;/ref&amp;gt;&lt;br /&gt;
libffi is a foreign function interface library. It provides a C programming language interface for calling natively compiled functions given information about the target function at run time instead of compile time. It also implements the opposite functionality: libffi can produce a pointer to a function that can accept and decode any combination of arguments defined at run time.&lt;br /&gt;
libffi is most often used as a bridging technology between compiled and interpreted language implementations. libffi may also be used to implement plug-ins, where the plug-in's function signatures are not known at the time of creating the host application.&lt;br /&gt;
Notable users include Python, Haskell, Dalvik, F-Script, PyPy, PyObjC, RubyCocoa, JRuby, Rubinius, MacRuby, gcj, GNU Smalltalk, IcedTea, Cycript, Pawn, Squeak, Java Native Access, Racket,&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Libffi#cite_note-2&amp;lt;/ref&amp;gt; Embeddable Common Lisp and Mozilla.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Libffi#cite_note-3&amp;lt;/ref&amp;gt;&lt;br /&gt;
On Mac OS X libffi is commonly used with BridgeSupport, which provides programming language neutral descriptions of framework interfaces, and Nu which binds direct Objective-C access from Lisp.&lt;br /&gt;
libffi has been widely ported and is released under a MIT license.&lt;br /&gt;
&lt;br /&gt;
===Ruby-FFI===&lt;br /&gt;
Ruby-FFI&amp;lt;ref&amp;gt;https://github.com/ffi/ffi/wiki&amp;lt;/ref&amp;gt; is a Foreign Function Interface extension for Ruby. It is an FFI extension doesn't need compilation and can be used on multi-platform and multi-implementation. Ruby-FFI extension is easy to read,write and maintain. In addition, it is impervious to changes in the internal Ruby API.&lt;br /&gt;
====Overall Architecture====&lt;br /&gt;
Using Ruby-FFI, you can use native libraries from Ruby without writing a single line of native code. Ruby-FFI takes care of all of the cross Ruby implementation (MRI, JRuby, Rubinius, MacRuby, etc) and platform specific issues so that you can focus on writing and testing your Ruby code.&lt;br /&gt;
&lt;br /&gt;
As FFI is effectively a bridge between the multiple worlds of Ruby implementations and multiple platform types, you might suffer a bit of cognitive dissonance trying to pull all the pieces together. When we develop in Ruby we tend to think in higher level terms, and don't so much concern ourselves with the lower level issues.&lt;br /&gt;
====Core Components====&lt;br /&gt;
Ruby-FFI has a number of useful components. Investing the time to understand FFI's components and capabilities will pay off as you begin using FFI. That said, it's nice to have an idea which components you should look at first. Understanding the following core modules and classes is a great way to start getting FFI's capabilities.&lt;br /&gt;
&lt;br /&gt;
*'''FFI::Library'''&lt;br /&gt;
Along with require 'ffi', this module brings FFI's powerful native library interfacing capabilities into your Ruby code as a DSL. Typically you extend your custom module with this one, specify the native libraries and their calling conventions, prototype the native library's functions and structs in Ruby, and then start using the native library's API from Ruby.&lt;br /&gt;
*'''FFI::Pointer''' &lt;br /&gt;
Wraps native memory allocated by a third party library. It provides a number of methods for transferring data from unmanaged native memory to Ruby-managed native memory (FFI::MemoryPointer). The native memory wrapped by this class is not freed during garbage collection runs.&lt;br /&gt;
*'''FFI::MemoryPointer'''&lt;br /&gt;
Allows for Ruby code to allocate native memory and pass it to non-Ruby libraries. Lifecycle management (allocation and deallocation) are handled by this class, so when it gets garbage collected the native memory is also freed.&lt;br /&gt;
*'''FFI::Struct and FFI::Union'''&lt;br /&gt;
&lt;br /&gt;
==How does it work?&amp;lt;ref&amp;gt;http://www.rubyinside.com/ruby-ffi-library-calling-external-libraries-now-easier-1293.html&amp;lt;/ref&amp;gt;==&lt;br /&gt;
The many compiled bridges between external libraries and Ruby pose a problem for alternate implementations like JRuby, because of the complexity involved in exposing internals of the implementation or expensive serialization in both directions. Instead, an interface is necessary so that instead of developing libraries that act only as unique bridges to others, we can just have one library that provides the interface to any arbitrary library of our choice.&lt;br /&gt;
&lt;br /&gt;
Ruby already has a library called &amp;quot;dl&amp;quot; that makes it possible to dynamically link external libraries with Ruby. It's a bit arcane though, and Charles points out that it's not widely used &amp;quot;because of real or perceived bugs.&amp;quot; Given this, and given the need for an implementation that can be compatible with JRuby, Wayne Meissner has developed &amp;quot;FFI&amp;quot;, a new Ruby library that provides &amp;quot;Foreign Function Interface&amp;quot; features to Ruby.&lt;br /&gt;
===Progress of FFI&amp;lt;ref&amp;gt;http://blog.headius.com/2008/10/ffi-for-ruby-now-available.html&amp;lt;/ref&amp;gt;===&lt;br /&gt;
One of the largest problems plaguing Ruby implementations is the ever-painful story of &amp;quot;extensions&amp;quot;. In general, these take the form of a dynamic library, usually written in C, that plugs into and calls Ruby's native API as exposed through ruby.h and libruby. Ignoring for the moment the fact that this API exposes way more of Ruby's internals than it should, extensions present a very difficult problem for other implementations:&lt;br /&gt;
&lt;br /&gt;
Do we support them or not?&lt;br /&gt;
&lt;br /&gt;
In many cases, this question is answered for us; most extensions require access to object internals we can't expose, or can't expose without extremely expensive copying back and forth. But there's also a silver lining: the vast majority of C-based extensions exist solely to wrap another library.&lt;br /&gt;
&lt;br /&gt;
Isn't it obvious what's needed here?&lt;br /&gt;
&lt;br /&gt;
This problem has been tackled by a number of libraries on a number of platforms. On the JVM, there's Java Native Access (JNA). On Python, there's ctypes. And even on Ruby, there's the &amp;quot;dl&amp;quot; stdlib, wrapping libdl for programmatic access to dynamic libraries. But dl is not widely used, because of real or perceived bugs and a rather arcane API. Something better is needed.&lt;br /&gt;
&lt;br /&gt;
Wayne is one of the primary maintainers of JNA, and has recently spent time on a new higher-performance version of it called JFFI. Wayne also became a JRuby committer this spring, and perhaps his most impressive contribution to date is a full FFI library for JRuby, based on JNA (eventually JFFI, once we migrate fully) and implementing the full set of what we and Evan agreed would be &amp;quot;FFI API 1.0&amp;quot;. We shipped the completed FFI support in JRuby 1.1.4.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;Passwd&amp;quot; and &amp;quot;Group&amp;quot; structures for functions like 'getpwuid':&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module Etc&lt;br /&gt;
  class Passwd &amp;lt; FFI::Struct&lt;br /&gt;
    layout :pw_name, :string, 0,&lt;br /&gt;
           :pw_passwd, :string, 4,&lt;br /&gt;
           :pw_uid, :uint, 8,&lt;br /&gt;
           :pw_gid, :uint, 12,&lt;br /&gt;
           :pw_dir, :string, 20,&lt;br /&gt;
           :pw_shell, :string, 24&lt;br /&gt;
  end&lt;br /&gt;
  class Group &amp;lt; FFI::Struct&lt;br /&gt;
    layout :gr_name, :string, 0,&lt;br /&gt;
           :gr_gid, :uint, 8&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In JRuby 1.1.5, we've taken another step forward with the API, adding support for callbacks. How would we represent a callback you pass into a C function from Ruby?&lt;br /&gt;
&lt;br /&gt;
Binding and calling &amp;quot;qsort&amp;quot; with an array of integers:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'ffi'&lt;br /&gt;
&lt;br /&gt;
module LibC&lt;br /&gt;
  extend FFI::Library&lt;br /&gt;
  callback :qsort_cmp, [ :pointer, :pointer ], :int&lt;br /&gt;
  attach_function :qsort, [ :pointer, :int, :int, :qsort_cmp ], :int&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
p = MemoryPointer.new(:int, 2)&lt;br /&gt;
p.put_array_of_int32(0, [ 2, 1 ])&lt;br /&gt;
puts &amp;quot;Before qsort #{p.get_array_of_int32(0, 2).join(', ')}&amp;quot;&lt;br /&gt;
LibC.qsort(p, 2, 4) do |p1, p2|&lt;br /&gt;
  i1 = p1.get_int32(0)&lt;br /&gt;
  i2 = p2.get_int32(0)&lt;br /&gt;
  i1 &amp;lt; i2 ? -1 : i1 &amp;gt; i2 ? 1 : 0&lt;br /&gt;
end&lt;br /&gt;
puts &amp;quot;After qsort #{p.get_array_of_int32(0, 2).join(', ')}&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What good is having such a library if it doesn't run everywhere? Up until recently, only Rubinius and JRuby supported FFI, which made our case for cross-implementation use pretty weak. Even though we were getting good use out of FFI, there was no motivation for anyone to use it in general, since the standard Ruby implementation had no support.&lt;br /&gt;
&lt;br /&gt;
That is, until Wayne pulled another rabbit out of his hat and implemented FFI for C Ruby as well. The JRuby team is proud to announce a wholly non-JRuby library: FFI is now available on Ruby 1.9 and Ruby 1.8.6/7, in addition to JRuby 1.1.4+ and Rubinius (though Rubinius does not yet support callbacks).&lt;br /&gt;
&lt;br /&gt;
Session showing installation and use of FFI in C Ruby:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ sudo gem install ffi&lt;br /&gt;
Password:&lt;br /&gt;
Building native extensions.  This could take a while...&lt;br /&gt;
Successfully installed ffi-0.1.1&lt;br /&gt;
1 gem installed&lt;br /&gt;
Installing ri documentation for ffi-0.1.1...&lt;br /&gt;
Installing RDoc documentation for ffi-0.1.1...&lt;br /&gt;
[headius @ cnutter:~]&lt;br /&gt;
$ irb&lt;br /&gt;
&amp;gt;&amp;gt; require 'ffi'&lt;br /&gt;
=&amp;gt; true&lt;br /&gt;
&amp;gt;&amp;gt; module RubyFFI&lt;br /&gt;
&amp;gt;&amp;gt; extend FFI::Library&lt;br /&gt;
&amp;gt;&amp;gt; attach_function :getuid, [], :uint&lt;br /&gt;
&amp;gt;&amp;gt; end&lt;br /&gt;
=&amp;gt; #&amp;lt;FFI::Invoker:0x1fe8c&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; puts RubyFFI.getuid&lt;br /&gt;
501&lt;br /&gt;
=&amp;gt; nil&lt;br /&gt;
&amp;gt;&amp;gt; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Our hope with JRuby's support of FFI and our release of FFI for C Ruby is that we may finally escape the hell of C extensions. &lt;br /&gt;
&lt;br /&gt;
A key feature that's not well documented is the use of FFI's templating system to generate bindings based on the current platform's header files. Here's a sample from the &amp;quot;Etc&amp;quot; module above.&lt;br /&gt;
&lt;br /&gt;
Etc module template, showing how to pull in header files and inspect a struct definition:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module Etc&lt;br /&gt;
  class Passwd &amp;lt; FFI::Struct&lt;br /&gt;
    @@@&lt;br /&gt;
    struct do |s|&lt;br /&gt;
      s.include &amp;quot;sys/types.h&amp;quot;&lt;br /&gt;
      s.include &amp;quot;pwd.h&amp;quot;&lt;br /&gt;
&lt;br /&gt;
      s.name &amp;quot;struct passwd&amp;quot;&lt;br /&gt;
      s.field :pw_name, :string&lt;br /&gt;
      s.field :pw_passwd, :string&lt;br /&gt;
      s.field :pw_uid, :uint&lt;br /&gt;
      s.field :pw_gid, :uint&lt;br /&gt;
      s.field :pw_dir, :string&lt;br /&gt;
      s.field :pw_shell, :string&lt;br /&gt;
    end&lt;br /&gt;
    @@@&lt;br /&gt;
  end&lt;br /&gt;
  class Group &amp;lt; FFI::Struct&lt;br /&gt;
    @@@&lt;br /&gt;
    struct do |s|&lt;br /&gt;
      s.include &amp;quot;sys/types.h&amp;quot;&lt;br /&gt;
      s.include &amp;quot;grp.h&amp;quot;&lt;br /&gt;
&lt;br /&gt;
      s.name &amp;quot;struct group&amp;quot;&lt;br /&gt;
      s.field :gr_name, :string&lt;br /&gt;
      s.field :gr_gid, :uint&lt;br /&gt;
    end&lt;br /&gt;
    @@@&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Basic Usage of Ruby-FFI&amp;lt;ref&amp;gt;https://github.com/ffi/ffi/wiki/Basic-Usage&amp;lt;/ref&amp;gt;===&lt;br /&gt;
Before showing the example, we would introduce several FFI's core components&amp;lt;ref&amp;gt;https://github.com/ffi/ffi/wiki/Core-Concepts#wiki-figure-1---overall-ffi-architecture&amp;lt;/ref&amp;gt;. Understanding the following core modules and classes is a great way to start getting FFI's capabilities:&lt;br /&gt;
&lt;br /&gt;
*FFI::Library - along with require 'ffi', this module provides FFI library interfacing capabilities into your Ruby code. Typically you need to extend your custom module with FFI::Library, specify the native libraries and their calling conventions, prototype the native library's functions and structs in Ruby, and then start using the native library's API from Ruby.&lt;br /&gt;
*FFI::Pointer - wraps native memory allocated by a third party library. It provides a number of methods for transferring data from unmanaged native memory to Ruby-managed native memory (FFI::MemoryPointer). The native memory wrapped by this class is not freed during garbage collection runs.&lt;br /&gt;
*FFI::MemoryPointer - allows for Ruby code to allocate native memory and pass it to non-Ruby libraries. Lifecycle management (allocation and deallocation) are handled by this class, so when it gets garbage collected the native memory is also freed.&lt;br /&gt;
*FFI::Struct and FFI::Union&lt;br /&gt;
&lt;br /&gt;
Here is a  &amp;quot;Hello, World&amp;quot; example how to use Ruby-FFI.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'ffi'&lt;br /&gt;
&lt;br /&gt;
module Hello&lt;br /&gt;
  extend FFI::Library&lt;br /&gt;
  ffi_lib FFI::Library::LIBC&lt;br /&gt;
  attach_function :puts, [ :string ], :int&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
Hello.puts(&amp;quot;Hello, World&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The interesting part above is the attach_function call. It requests that a C function named puts which takes a :string argument and returns an :int, be attached to the Hello module.&lt;br /&gt;
&lt;br /&gt;
The attach_function method locates the C function in a specific external library (i.e. libc in the example). The name of the function, the parameter types and the return type are needed. In the above example, attach_function locates a function named puts, which papameter type and return type are :string and :int respectively.&lt;br /&gt;
&lt;br /&gt;
The typical parameter and return types&amp;lt;ref&amp;gt;https://github.com/ffi/ffi/wiki/Types&amp;lt;/ref&amp;gt; are listed here: &lt;br /&gt;
&lt;br /&gt;
* :char and :uchar - 8 bit signed and unsigned values&lt;br /&gt;
* :short and :ushort - 16 bit signed and unsigned values&lt;br /&gt;
* :int and :uint - 32 bit signed and unsigned values&lt;br /&gt;
* :long_long and :ulong_long - 64 bit signed and unsigned values&lt;br /&gt;
* :long and :ulong - native cpu word (32 bit or 64bit) signed and unsigned values. Equivalent to C 'long' type.&lt;br /&gt;
* :float and :double&lt;br /&gt;
* :string - C string, NULL terminated.&lt;br /&gt;
* :pointer - a C pointer&lt;br /&gt;
&lt;br /&gt;
You can also pass the struct as parameter. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
typedef struct _WHAT {&lt;br /&gt;
  int d;&lt;br /&gt;
} WHAT;&lt;br /&gt;
&lt;br /&gt;
int doit(WHAT w) {&lt;br /&gt;
  printf(&amp;quot;%d\n&amp;quot;, w.d);&lt;br /&gt;
  return w.d;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class WHAT &amp;lt; FFI::Struct&lt;br /&gt;
  layout :d, :int&lt;br /&gt;
end&lt;br /&gt;
attach_function 'doit', [ WHAT.by_value ], :int&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above 2 pieces of code, attach_function uses struct WHAT as a parameter type.&lt;br /&gt;
&lt;br /&gt;
===Docs on FFI===&lt;br /&gt;
[http://wiki.jruby.org/wiki/Calling_C_from_JRuby Calling C from JRuby]&amp;lt;br/&amp;gt;&lt;br /&gt;
[http://blog.segment7.net/articles/2008/01/15/rubinius-foreign-function-interfaceRubinius's Foreign Function Interface]&amp;lt;br/&amp;gt;&lt;br /&gt;
[http://pluskid.lifegoo.com/?p=370On the Rubinius FFI]&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Who uses it?==&lt;br /&gt;
The libffi library is useful to anyone trying to build a bridge between interpreted and natively compiled code. Some notable users include:&lt;br /&gt;
*CPython - the default, most-widely used implementation of the Python programming language uses libffi in the standard ctypes library.&lt;br /&gt;
*OpenJDK - the open-source implementation of the Java Platform Standard Edition uses libffi to bridge between the interpreter and native code for some platforms.&lt;br /&gt;
*js-ctypes - a foreign function interface for javascript that Mozilla will be shipping in Firefox 3.6.&lt;br /&gt;
*Dalvik - Dalvik is the virtual machine which runs the Java platform on Android mobile devices. libffi is used on Android ports for which no custom bridging code has been written.&lt;br /&gt;
*Java Native Access (JNA) - the JNI-free way to call native code from Java.&lt;br /&gt;
*Ruby-FFI - a Foreign Function Interface extension for Ruby.&lt;br /&gt;
*fsbv - Foreign Structure By Value is a foreign function interface library for Common Lisp that extends the standard CFFI package to include support for passing structure arguments by value.&lt;br /&gt;
*JSCocoa - call Objective-C code from javascript on Mac OSX and the iPhone (via the libffi-iphone port).&lt;br /&gt;
*PyObjC - call Objective-C code from Python on Mac OSX.&lt;br /&gt;
*RubyCocoa - call Objective-C code from Ruby on Mac OSX.&lt;br /&gt;
*PLT Scheme - call C code from this popular Scheme implementation (also used as the implementation platform for Paul Graham's new Lisp, Arc).&lt;br /&gt;
*gcj - the runtime library for the GNU Compiler for the Java Programming Language uses libffi to handle calls back and forth between interpreted and natively compiled code. gcj is part of the GCC, the GNU Compiler Collection.&lt;br /&gt;
&lt;br /&gt;
==Supported Platforms==&lt;br /&gt;
Libffi has been ported to many different platforms. For specific configuration details and testing status, please refer to the wiki page [http://www.moxielogic.org/wiki/index.php?title=Libffi_3.0.13 here]&lt;br /&gt;
&lt;br /&gt;
==Adoption==&lt;br /&gt;
[http://ruby-doc.org/stdlib-2.0/libdoc/fiddle/rdoc/index.html Fiddle]&amp;lt;br/&amp;gt;&lt;br /&gt;
A libffi wrapper in the Ruby Standard Library&amp;lt;br/&amp;gt;&lt;br /&gt;
[http://github.com/ffi/ffi Ruby-FFI]&amp;lt;br/&amp;gt;&lt;br /&gt;
A Foreign Function Interface extension for Ruby.&amp;lt;br/&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/RubyCocoa  RubyCocoa]&amp;lt;br/&amp;gt;&lt;br /&gt;
Call Objective-C code from Ruby on Mac OSX.&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
http://en.wikipedia.org/wiki/Libffi&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''References''' ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
*http://github.com/atgreen/libffi/blob/master/LICENSE&lt;br /&gt;
*http://repository.readscheme.org/ftp/papers/sw2004/barzilay.pdf&lt;br /&gt;
*http://hg.mozilla.org/mozilla-central/file/2dc00d4b379a/js/ctypes/libffi&lt;br /&gt;
*https://developer.mozilla.org/en/js-ctypes&lt;br /&gt;
*https://developer.mozilla.org/en/js-ctypes/js-ctypes_reference&lt;br /&gt;
*http://blog.headius.com/2008/10/ffi-for-ruby-now-available.html&lt;br /&gt;
*http://www.rubyinside.com/ruby-ffi-library-calling-external-libraries-now-easier-1293.html&lt;br /&gt;
*http://sourceware.org/libffi/&lt;/div&gt;</summary>
		<author><name>Qjia2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1h_jg&amp;diff=83146</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1h jg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1h_jg&amp;diff=83146"/>
		<updated>2014-02-10T21:19:41Z</updated>

		<summary type="html">&lt;p&gt;Qjia2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== '''Ruby libraries to load objects of other languages at run time''' ==&lt;br /&gt;
&lt;br /&gt;
This is an advanced topic. Libraries are being developed where Ruby gems can load libraries (and even native code) of other languages.A few open-source projects like FFI are currently working on this. Previous version is available [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/ch1_1w21_w here]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
==Introduction==&lt;br /&gt;
===Runtime Library===&lt;br /&gt;
In computer programming, a runtime library is the API used by a compiler to invoke some of the behaviors of a runtime system. The runtime system implements the execution model and other fundamental behaviors of a programming language. The compiler inserts calls to the runtime library into the executable binary. During execution (run time) of that computer program, execution of those calls to the runtime library cause communication between the application and the runtime system. This often includes functions for input and output, or for memory management.&lt;br /&gt;
The runtime library may implement a portion of the runtime system's behavior, but if one reads the code of the calls available, they typically are thin wrappers that simply package information and send it to the runtime system. However, sometimes the term runtime library is meant to include the code of the runtime system itself, even though much of that code cannot be directly reached via a library call.&lt;br /&gt;
&lt;br /&gt;
For example, some language features that can be performed only (or are more efficient or accurate) at runtime are implemented in the runtime system and may be invoked via the runtime library API, e.g. some logic errors, array bounds checking, dynamic type checking, exception handling and possibly debugging functionality. For this reason, some programming bugs are not discovered until the program is tested in a &amp;quot;live&amp;quot; environment with real data, despite sophisticated compile-time checking and pre-release testing. In this case, the end user may encounter a runtime error message.&lt;br /&gt;
&lt;br /&gt;
The concept of a runtime library should not be confused with an ordinary program library like that created by an application programmer or delivered by a third party, nor with a dynamic library, meaning a program library linked at run time.&lt;br /&gt;
&lt;br /&gt;
===libffi===&lt;br /&gt;
FFI stands for Foreign Function Interface. A foreign function interface is the popular name for the interface that allows code written in one language to call code written in another language. The libffi was originally written by Anthony Green&amp;lt;ref&amp;gt;http://moxielogic.org/blog&amp;lt;/ref&amp;gt;. The libffi library really only provides the lowest, machine dependent layer of a fully featured foreign function interface. A layer must exist above libffi that handles type conversions for values passed between the two languages.&amp;lt;ref&amp;gt;http://sourceware.org/libffi/&amp;lt;/ref&amp;gt;&lt;br /&gt;
libffi is a foreign function interface library. It provides a C programming language interface for calling natively compiled functions given information about the target function at run time instead of compile time. It also implements the opposite functionality: libffi can produce a pointer to a function that can accept and decode any combination of arguments defined at run time.&lt;br /&gt;
libffi is most often used as a bridging technology between compiled and interpreted language implementations. libffi may also be used to implement plug-ins, where the plug-in's function signatures are not known at the time of creating the host application.&lt;br /&gt;
Notable users include Python, Haskell, Dalvik, F-Script, PyPy, PyObjC, RubyCocoa, JRuby, Rubinius, MacRuby, gcj, GNU Smalltalk, IcedTea, Cycript, Pawn, Squeak, Java Native Access, Racket,&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Libffi#cite_note-2&amp;lt;/ref&amp;gt; Embeddable Common Lisp and Mozilla.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Libffi#cite_note-3&amp;lt;/ref&amp;gt;&lt;br /&gt;
On Mac OS X libffi is commonly used with BridgeSupport, which provides programming language neutral descriptions of framework interfaces, and Nu which binds direct Objective-C access from Lisp.&lt;br /&gt;
libffi has been widely ported and is released under a MIT license.&lt;br /&gt;
&lt;br /&gt;
===Ruby-FFI===&lt;br /&gt;
Ruby-FFI&amp;lt;ref&amp;gt;https://github.com/ffi/ffi/wiki&amp;lt;/ref&amp;gt; is a Foreign Function Interface extension for Ruby. It is an FFI extension doesn't need compilation and can be used on multi-platform and multi-implementation. Ruby-FFI extension is easy to read,write and maintain. In addition, it is impervious to changes in the internal Ruby API.&lt;br /&gt;
====Overall Architecture====&lt;br /&gt;
Using Ruby-FFI, you can use native libraries from Ruby without writing a single line of native code. Ruby-FFI takes care of all of the cross Ruby implementation (MRI, JRuby, Rubinius, MacRuby, etc) and platform specific issues so that you can focus on writing and testing your Ruby code.&lt;br /&gt;
As FFI is effectively a bridge between the multiple worlds of Ruby implementations and multiple platform types, you might suffer a bit of cognitive dissonance trying to pull all the pieces together. When we develop in Ruby we tend to think in higher level terms, and don't so much concern ourselves with the lower level issues.&lt;br /&gt;
====Core Components====&lt;br /&gt;
Ruby-FFI has a number of useful components. Investing the time to understand FFI's components and capabilities will pay off as you begin using FFI. That said, it's nice to have an idea which components you should look at first. Understanding the following core modules and classes is a great way to start getting FFI's capabilities.&lt;br /&gt;
&lt;br /&gt;
*'''FFI::Library'''&lt;br /&gt;
Along with require 'ffi', this module brings FFI's powerful native library interfacing capabilities into your Ruby code as a DSL. Typically you extend your custom module with this one, specify the native libraries and their calling conventions, prototype the native library's functions and structs in Ruby, and then start using the native library's API from Ruby.&lt;br /&gt;
*'''FFI::Pointer''' &lt;br /&gt;
Wraps native memory allocated by a third party library. It provides a number of methods for transferring data from unmanaged native memory to Ruby-managed native memory (FFI::MemoryPointer). The native memory wrapped by this class is not freed during garbage collection runs.&lt;br /&gt;
*'''FFI::MemoryPointer'''&lt;br /&gt;
Allows for Ruby code to allocate native memory and pass it to non-Ruby libraries. Lifecycle management (allocation and deallocation) are handled by this class, so when it gets garbage collected the native memory is also freed.&lt;br /&gt;
*'''FFI::Struct and FFI::Union'''&lt;br /&gt;
&lt;br /&gt;
==How does it work?&amp;lt;ref&amp;gt;http://www.rubyinside.com/ruby-ffi-library-calling-external-libraries-now-easier-1293.html&amp;lt;/ref&amp;gt;==&lt;br /&gt;
The many compiled bridges between external libraries and Ruby pose a problem for alternate implementations like JRuby, because of the complexity involved in exposing internals of the implementation or expensive serialization in both directions. Instead, an interface is necessary so that instead of developing libraries that act only as unique bridges to others, we can just have one library that provides the interface to any arbitrary library of our choice.&lt;br /&gt;
&lt;br /&gt;
Ruby already has a library called &amp;quot;dl&amp;quot; that makes it possible to dynamically link external libraries with Ruby. It's a bit arcane though, and Charles points out that it's not widely used &amp;quot;because of real or perceived bugs.&amp;quot; Given this, and given the need for an implementation that can be compatible with JRuby, Wayne Meissner has developed &amp;quot;FFI&amp;quot;, a new Ruby library that provides &amp;quot;Foreign Function Interface&amp;quot; features to Ruby.&lt;br /&gt;
===Progress of FFI&amp;lt;ref&amp;gt;http://blog.headius.com/2008/10/ffi-for-ruby-now-available.html&amp;lt;/ref&amp;gt;===&lt;br /&gt;
One of the largest problems plaguing Ruby implementations is the ever-painful story of &amp;quot;extensions&amp;quot;. In general, these take the form of a dynamic library, usually written in C, that plugs into and calls Ruby's native API as exposed through ruby.h and libruby. Ignoring for the moment the fact that this API exposes way more of Ruby's internals than it should, extensions present a very difficult problem for other implementations:&lt;br /&gt;
&lt;br /&gt;
Do we support them or not?&lt;br /&gt;
&lt;br /&gt;
In many cases, this question is answered for us; most extensions require access to object internals we can't expose, or can't expose without extremely expensive copying back and forth. But there's also a silver lining: the vast majority of C-based extensions exist solely to wrap another library.&lt;br /&gt;
&lt;br /&gt;
Isn't it obvious what's needed here?&lt;br /&gt;
&lt;br /&gt;
This problem has been tackled by a number of libraries on a number of platforms. On the JVM, there's Java Native Access (JNA). On Python, there's ctypes. And even on Ruby, there's the &amp;quot;dl&amp;quot; stdlib, wrapping libdl for programmatic access to dynamic libraries. But dl is not widely used, because of real or perceived bugs and a rather arcane API. Something better is needed.&lt;br /&gt;
&lt;br /&gt;
Wayne is one of the primary maintainers of JNA, and has recently spent time on a new higher-performance version of it called JFFI. Wayne also became a JRuby committer this spring, and perhaps his most impressive contribution to date is a full FFI library for JRuby, based on JNA (eventually JFFI, once we migrate fully) and implementing the full set of what we and Evan agreed would be &amp;quot;FFI API 1.0&amp;quot;. We shipped the completed FFI support in JRuby 1.1.4.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;Passwd&amp;quot; and &amp;quot;Group&amp;quot; structures for functions like 'getpwuid':&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module Etc&lt;br /&gt;
  class Passwd &amp;lt; FFI::Struct&lt;br /&gt;
    layout :pw_name, :string, 0,&lt;br /&gt;
           :pw_passwd, :string, 4,&lt;br /&gt;
           :pw_uid, :uint, 8,&lt;br /&gt;
           :pw_gid, :uint, 12,&lt;br /&gt;
           :pw_dir, :string, 20,&lt;br /&gt;
           :pw_shell, :string, 24&lt;br /&gt;
  end&lt;br /&gt;
  class Group &amp;lt; FFI::Struct&lt;br /&gt;
    layout :gr_name, :string, 0,&lt;br /&gt;
           :gr_gid, :uint, 8&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In JRuby 1.1.5, we've taken another step forward with the API, adding support for callbacks. How would we represent a callback you pass into a C function from Ruby?&lt;br /&gt;
&lt;br /&gt;
Binding and calling &amp;quot;qsort&amp;quot; with an array of integers:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'ffi'&lt;br /&gt;
&lt;br /&gt;
module LibC&lt;br /&gt;
  extend FFI::Library&lt;br /&gt;
  callback :qsort_cmp, [ :pointer, :pointer ], :int&lt;br /&gt;
  attach_function :qsort, [ :pointer, :int, :int, :qsort_cmp ], :int&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
p = MemoryPointer.new(:int, 2)&lt;br /&gt;
p.put_array_of_int32(0, [ 2, 1 ])&lt;br /&gt;
puts &amp;quot;Before qsort #{p.get_array_of_int32(0, 2).join(', ')}&amp;quot;&lt;br /&gt;
LibC.qsort(p, 2, 4) do |p1, p2|&lt;br /&gt;
  i1 = p1.get_int32(0)&lt;br /&gt;
  i2 = p2.get_int32(0)&lt;br /&gt;
  i1 &amp;lt; i2 ? -1 : i1 &amp;gt; i2 ? 1 : 0&lt;br /&gt;
end&lt;br /&gt;
puts &amp;quot;After qsort #{p.get_array_of_int32(0, 2).join(', ')}&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What good is having such a library if it doesn't run everywhere? Up until recently, only Rubinius and JRuby supported FFI, which made our case for cross-implementation use pretty weak. Even though we were getting good use out of FFI, there was no motivation for anyone to use it in general, since the standard Ruby implementation had no support.&lt;br /&gt;
&lt;br /&gt;
That is, until Wayne pulled another rabbit out of his hat and implemented FFI for C Ruby as well. The JRuby team is proud to announce a wholly non-JRuby library: FFI is now available on Ruby 1.9 and Ruby 1.8.6/7, in addition to JRuby 1.1.4+ and Rubinius (though Rubinius does not yet support callbacks).&lt;br /&gt;
&lt;br /&gt;
Session showing installation and use of FFI in C Ruby:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ sudo gem install ffi&lt;br /&gt;
Password:&lt;br /&gt;
Building native extensions.  This could take a while...&lt;br /&gt;
Successfully installed ffi-0.1.1&lt;br /&gt;
1 gem installed&lt;br /&gt;
Installing ri documentation for ffi-0.1.1...&lt;br /&gt;
Installing RDoc documentation for ffi-0.1.1...&lt;br /&gt;
[headius @ cnutter:~]&lt;br /&gt;
$ irb&lt;br /&gt;
&amp;gt;&amp;gt; require 'ffi'&lt;br /&gt;
=&amp;gt; true&lt;br /&gt;
&amp;gt;&amp;gt; module RubyFFI&lt;br /&gt;
&amp;gt;&amp;gt; extend FFI::Library&lt;br /&gt;
&amp;gt;&amp;gt; attach_function :getuid, [], :uint&lt;br /&gt;
&amp;gt;&amp;gt; end&lt;br /&gt;
=&amp;gt; #&amp;lt;FFI::Invoker:0x1fe8c&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; puts RubyFFI.getuid&lt;br /&gt;
501&lt;br /&gt;
=&amp;gt; nil&lt;br /&gt;
&amp;gt;&amp;gt; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Our hope with JRuby's support of FFI and our release of FFI for C Ruby is that we may finally escape the hell of C extensions. &lt;br /&gt;
&lt;br /&gt;
A key feature that's not well documented is the use of FFI's templating system to generate bindings based on the current platform's header files. Here's a sample from the &amp;quot;Etc&amp;quot; module above.&lt;br /&gt;
&lt;br /&gt;
Etc module template, showing how to pull in header files and inspect a struct definition:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module Etc&lt;br /&gt;
  class Passwd &amp;lt; FFI::Struct&lt;br /&gt;
    @@@&lt;br /&gt;
    struct do |s|&lt;br /&gt;
      s.include &amp;quot;sys/types.h&amp;quot;&lt;br /&gt;
      s.include &amp;quot;pwd.h&amp;quot;&lt;br /&gt;
&lt;br /&gt;
      s.name &amp;quot;struct passwd&amp;quot;&lt;br /&gt;
      s.field :pw_name, :string&lt;br /&gt;
      s.field :pw_passwd, :string&lt;br /&gt;
      s.field :pw_uid, :uint&lt;br /&gt;
      s.field :pw_gid, :uint&lt;br /&gt;
      s.field :pw_dir, :string&lt;br /&gt;
      s.field :pw_shell, :string&lt;br /&gt;
    end&lt;br /&gt;
    @@@&lt;br /&gt;
  end&lt;br /&gt;
  class Group &amp;lt; FFI::Struct&lt;br /&gt;
    @@@&lt;br /&gt;
    struct do |s|&lt;br /&gt;
      s.include &amp;quot;sys/types.h&amp;quot;&lt;br /&gt;
      s.include &amp;quot;grp.h&amp;quot;&lt;br /&gt;
&lt;br /&gt;
      s.name &amp;quot;struct group&amp;quot;&lt;br /&gt;
      s.field :gr_name, :string&lt;br /&gt;
      s.field :gr_gid, :uint&lt;br /&gt;
    end&lt;br /&gt;
    @@@&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Basic Usage of Ruby-FFI&amp;lt;ref&amp;gt;https://github.com/ffi/ffi/wiki/Basic-Usage&amp;lt;/ref&amp;gt;===&lt;br /&gt;
Before showing the example, we would introduce several FFI's core components&amp;lt;ref&amp;gt;https://github.com/ffi/ffi/wiki/Core-Concepts#wiki-figure-1---overall-ffi-architecture&amp;lt;/ref&amp;gt;. Understanding the following core modules and classes is a great way to start getting FFI's capabilities:&lt;br /&gt;
&lt;br /&gt;
*FFI::Library - along with require 'ffi', this module provides FFI library interfacing capabilities into your Ruby code. Typically you need to extend your custom module with FFI::Library, specify the native libraries and their calling conventions, prototype the native library's functions and structs in Ruby, and then start using the native library's API from Ruby.&lt;br /&gt;
*FFI::Pointer - wraps native memory allocated by a third party library. It provides a number of methods for transferring data from unmanaged native memory to Ruby-managed native memory (FFI::MemoryPointer). The native memory wrapped by this class is not freed during garbage collection runs.&lt;br /&gt;
*FFI::MemoryPointer - allows for Ruby code to allocate native memory and pass it to non-Ruby libraries. Lifecycle management (allocation and deallocation) are handled by this class, so when it gets garbage collected the native memory is also freed.&lt;br /&gt;
*FFI::Struct and FFI::Union&lt;br /&gt;
&lt;br /&gt;
Here is a  &amp;quot;Hello, World&amp;quot; example how to use Ruby-FFI.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'ffi'&lt;br /&gt;
&lt;br /&gt;
module Hello&lt;br /&gt;
  extend FFI::Library&lt;br /&gt;
  ffi_lib FFI::Library::LIBC&lt;br /&gt;
  attach_function :puts, [ :string ], :int&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
Hello.puts(&amp;quot;Hello, World&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The interesting part above is the attach_function call. It requests that a C function named puts which takes a :string argument and returns an :int, be attached to the Hello module.&lt;br /&gt;
&lt;br /&gt;
The attach_function method locates the C function in a specific external library (i.e. libc in the example). The name of the function, the parameter types and the return type are needed. In the above example, attach_function locates a function named puts, which papameter type and return type are :string and :int respectively.&lt;br /&gt;
&lt;br /&gt;
The typical parameter and return types&amp;lt;ref&amp;gt;https://github.com/ffi/ffi/wiki/Types&amp;lt;/ref&amp;gt; are listed here: &lt;br /&gt;
&lt;br /&gt;
* :char and :uchar - 8 bit signed and unsigned values&lt;br /&gt;
* :short and :ushort - 16 bit signed and unsigned values&lt;br /&gt;
* :int and :uint - 32 bit signed and unsigned values&lt;br /&gt;
* :long_long and :ulong_long - 64 bit signed and unsigned values&lt;br /&gt;
* :long and :ulong - native cpu word (32 bit or 64bit) signed and unsigned values. Equivalent to C 'long' type.&lt;br /&gt;
* :float and :double&lt;br /&gt;
* :string - C string, NULL terminated.&lt;br /&gt;
* :pointer - a C pointer&lt;br /&gt;
&lt;br /&gt;
You can also pass the struct as parameter. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
typedef struct _WHAT {&lt;br /&gt;
  int d;&lt;br /&gt;
} WHAT;&lt;br /&gt;
&lt;br /&gt;
int doit(WHAT w) {&lt;br /&gt;
  printf(&amp;quot;%d\n&amp;quot;, w.d);&lt;br /&gt;
  return w.d;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class WHAT &amp;lt; FFI::Struct&lt;br /&gt;
  layout :d, :int&lt;br /&gt;
end&lt;br /&gt;
attach_function 'doit', [ WHAT.by_value ], :int&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above 2 pieces of code, attach_function uses struct WHAT as a parameter type.&lt;br /&gt;
&lt;br /&gt;
===Docs on FFI===&lt;br /&gt;
[http://wiki.jruby.org/wiki/Calling_C_from_JRuby Calling C from JRuby]&amp;lt;br/&amp;gt;&lt;br /&gt;
[http://blog.segment7.net/articles/2008/01/15/rubinius-foreign-function-interfaceRubinius's Foreign Function Interface]&amp;lt;br/&amp;gt;&lt;br /&gt;
[http://pluskid.lifegoo.com/?p=370On the Rubinius FFI]&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Who uses it?==&lt;br /&gt;
The libffi library is useful to anyone trying to build a bridge between interpreted and natively compiled code. Some notable users include:&lt;br /&gt;
*CPython - the default, most-widely used implementation of the Python programming language uses libffi in the standard ctypes library.&lt;br /&gt;
*OpenJDK - the open-source implementation of the Java Platform Standard Edition uses libffi to bridge between the interpreter and native code for some platforms.&lt;br /&gt;
*js-ctypes - a foreign function interface for javascript that Mozilla will be shipping in Firefox 3.6.&lt;br /&gt;
*Dalvik - Dalvik is the virtual machine which runs the Java platform on Android mobile devices. libffi is used on Android ports for which no custom bridging code has been written.&lt;br /&gt;
*Java Native Access (JNA) - the JNI-free way to call native code from Java.&lt;br /&gt;
*Ruby-FFI - a Foreign Function Interface extension for Ruby.&lt;br /&gt;
*fsbv - Foreign Structure By Value is a foreign function interface library for Common Lisp that extends the standard CFFI package to include support for passing structure arguments by value.&lt;br /&gt;
*JSCocoa - call Objective-C code from javascript on Mac OSX and the iPhone (via the libffi-iphone port).&lt;br /&gt;
*PyObjC - call Objective-C code from Python on Mac OSX.&lt;br /&gt;
*RubyCocoa - call Objective-C code from Ruby on Mac OSX.&lt;br /&gt;
*PLT Scheme - call C code from this popular Scheme implementation (also used as the implementation platform for Paul Graham's new Lisp, Arc).&lt;br /&gt;
*gcj - the runtime library for the GNU Compiler for the Java Programming Language uses libffi to handle calls back and forth between interpreted and natively compiled code. gcj is part of the GCC, the GNU Compiler Collection.&lt;br /&gt;
&lt;br /&gt;
==Supported Platforms==&lt;br /&gt;
Libffi has been ported to many different platforms. For specific configuration details and testing status, please refer to the wiki page [http://www.moxielogic.org/wiki/index.php?title=Libffi_3.0.13 here]&lt;br /&gt;
&lt;br /&gt;
==Adoption==&lt;br /&gt;
[http://ruby-doc.org/stdlib-2.0/libdoc/fiddle/rdoc/index.html Fiddle]&amp;lt;br/&amp;gt;&lt;br /&gt;
A libffi wrapper in the Ruby Standard Library&amp;lt;br/&amp;gt;&lt;br /&gt;
[http://github.com/ffi/ffi Ruby-FFI]&amp;lt;br/&amp;gt;&lt;br /&gt;
A Foreign Function Interface extension for Ruby.&amp;lt;br/&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/RubyCocoa  RubyCocoa]&amp;lt;br/&amp;gt;&lt;br /&gt;
Call Objective-C code from Ruby on Mac OSX.&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
http://en.wikipedia.org/wiki/Libffi&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''References''' ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
*http://github.com/atgreen/libffi/blob/master/LICENSE&lt;br /&gt;
*http://repository.readscheme.org/ftp/papers/sw2004/barzilay.pdf&lt;br /&gt;
*http://hg.mozilla.org/mozilla-central/file/2dc00d4b379a/js/ctypes/libffi&lt;br /&gt;
*https://developer.mozilla.org/en/js-ctypes&lt;br /&gt;
*https://developer.mozilla.org/en/js-ctypes/js-ctypes_reference&lt;br /&gt;
*http://blog.headius.com/2008/10/ffi-for-ruby-now-available.html&lt;br /&gt;
*http://www.rubyinside.com/ruby-ffi-library-calling-external-libraries-now-easier-1293.html&lt;br /&gt;
*http://sourceware.org/libffi/&lt;/div&gt;</summary>
		<author><name>Qjia2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1h_jg&amp;diff=83144</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1h jg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1h_jg&amp;diff=83144"/>
		<updated>2014-02-10T21:17:20Z</updated>

		<summary type="html">&lt;p&gt;Qjia2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== '''Ruby libraries to load objects of other languages at run time''' ==&lt;br /&gt;
&lt;br /&gt;
This is an advanced topic. Libraries are being developed where Ruby gems can load libraries (and even native code) of other languages.A few open-source projects like FFI are currently working on this. Previous version is available [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/ch1_1w21_w here]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
==Introduction==&lt;br /&gt;
===Runtime Library===&lt;br /&gt;
In computer programming, a runtime library is the API used by a compiler to invoke some of the behaviors of a runtime system. The runtime system implements the execution model and other fundamental behaviors of a programming language. The compiler inserts calls to the runtime library into the executable binary. During execution (run time) of that computer program, execution of those calls to the runtime library cause communication between the application and the runtime system. This often includes functions for input and output, or for memory management.&lt;br /&gt;
The runtime library may implement a portion of the runtime system's behavior, but if one reads the code of the calls available, they typically are thin wrappers that simply package information and send it to the runtime system. However, sometimes the term runtime library is meant to include the code of the runtime system itself, even though much of that code cannot be directly reached via a library call.&lt;br /&gt;
&lt;br /&gt;
For example, some language features that can be performed only (or are more efficient or accurate) at runtime are implemented in the runtime system and may be invoked via the runtime library API, e.g. some logic errors, array bounds checking, dynamic type checking, exception handling and possibly debugging functionality. For this reason, some programming bugs are not discovered until the program is tested in a &amp;quot;live&amp;quot; environment with real data, despite sophisticated compile-time checking and pre-release testing. In this case, the end user may encounter a runtime error message.&lt;br /&gt;
&lt;br /&gt;
The concept of a runtime library should not be confused with an ordinary program library like that created by an application programmer or delivered by a third party, nor with a dynamic library, meaning a program library linked at run time.&lt;br /&gt;
&lt;br /&gt;
===libffi===&lt;br /&gt;
FFI stands for Foreign Function Interface. A foreign function interface is the popular name for the interface that allows code written in one language to call code written in another language. The libffi was originally written by Anthony Green&amp;lt;ref&amp;gt;http://moxielogic.org/blog&amp;lt;/ref&amp;gt;. The libffi library really only provides the lowest, machine dependent layer of a fully featured foreign function interface. A layer must exist above libffi that handles type conversions for values passed between the two languages.&amp;lt;ref&amp;gt;http://sourceware.org/libffi/&amp;lt;/ref&amp;gt;&lt;br /&gt;
libffi is a foreign function interface library. It provides a C programming language interface for calling natively compiled functions given information about the target function at run time instead of compile time. It also implements the opposite functionality: libffi can produce a pointer to a function that can accept and decode any combination of arguments defined at run time.&lt;br /&gt;
libffi is most often used as a bridging technology between compiled and interpreted language implementations. libffi may also be used to implement plug-ins, where the plug-in's function signatures are not known at the time of creating the host application.&lt;br /&gt;
Notable users include Python, Haskell, Dalvik, F-Script, PyPy, PyObjC, RubyCocoa, JRuby, Rubinius, MacRuby, gcj, GNU Smalltalk, IcedTea, Cycript, Pawn, Squeak, Java Native Access, Racket,&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Libffi#cite_note-2&amp;lt;/ref&amp;gt; Embeddable Common Lisp and Mozilla.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Libffi#cite_note-3&amp;lt;/ref&amp;gt;&lt;br /&gt;
On Mac OS X libffi is commonly used with BridgeSupport, which provides programming language neutral descriptions of framework interfaces, and Nu which binds direct Objective-C access from Lisp.&lt;br /&gt;
libffi has been widely ported and is released under a MIT license.&lt;br /&gt;
&lt;br /&gt;
===Ruby-FFI===&lt;br /&gt;
Ruby-FFI&amp;lt;ref&amp;gt;https://github.com/ffi/ffi/wiki&amp;lt;/ref&amp;gt; is a Foreign Function Interface extension for Ruby. It is an FFI extension doesn't need compilation and can be used on multi-platform and multi-implementation. Ruby-FFI extension is easy to read,write and maintain. In addition, it is impervious to changes in the internal Ruby API.&lt;br /&gt;
====Core Components====&lt;br /&gt;
Ruby-FFI has a number of useful components. Investing the time to understand FFI's components and capabilities will pay off as you begin using FFI. That said, it's nice to have an idea which components you should look at first. Understanding the following core modules and classes is a great way to start getting FFI's capabilities.&lt;br /&gt;
&lt;br /&gt;
*'''FFI::Library'''&lt;br /&gt;
Along with require 'ffi', this module brings FFI's powerful native library interfacing capabilities into your Ruby code as a DSL. Typically you extend your custom module with this one, specify the native libraries and their calling conventions, prototype the native library's functions and structs in Ruby, and then start using the native library's API from Ruby.&lt;br /&gt;
*'''FFI::Pointer''' &lt;br /&gt;
Wraps native memory allocated by a third party library. It provides a number of methods for transferring data from unmanaged native memory to Ruby-managed native memory (FFI::MemoryPointer). The native memory wrapped by this class is not freed during garbage collection runs.&lt;br /&gt;
*'''FFI::MemoryPointer'''&lt;br /&gt;
Allows for Ruby code to allocate native memory and pass it to non-Ruby libraries. Lifecycle management (allocation and deallocation) are handled by this class, so when it gets garbage collected the native memory is also freed.&lt;br /&gt;
*'''FFI::Struct and FFI::Union'''&lt;br /&gt;
&lt;br /&gt;
==How does it work?&amp;lt;ref&amp;gt;http://www.rubyinside.com/ruby-ffi-library-calling-external-libraries-now-easier-1293.html&amp;lt;/ref&amp;gt;==&lt;br /&gt;
The many compiled bridges between external libraries and Ruby pose a problem for alternate implementations like JRuby, because of the complexity involved in exposing internals of the implementation or expensive serialization in both directions. Instead, an interface is necessary so that instead of developing libraries that act only as unique bridges to others, we can just have one library that provides the interface to any arbitrary library of our choice.&lt;br /&gt;
&lt;br /&gt;
Ruby already has a library called &amp;quot;dl&amp;quot; that makes it possible to dynamically link external libraries with Ruby. It's a bit arcane though, and Charles points out that it's not widely used &amp;quot;because of real or perceived bugs.&amp;quot; Given this, and given the need for an implementation that can be compatible with JRuby, Wayne Meissner has developed &amp;quot;FFI&amp;quot;, a new Ruby library that provides &amp;quot;Foreign Function Interface&amp;quot; features to Ruby.&lt;br /&gt;
===Progress of FFI&amp;lt;ref&amp;gt;http://blog.headius.com/2008/10/ffi-for-ruby-now-available.html&amp;lt;/ref&amp;gt;===&lt;br /&gt;
One of the largest problems plaguing Ruby implementations is the ever-painful story of &amp;quot;extensions&amp;quot;. In general, these take the form of a dynamic library, usually written in C, that plugs into and calls Ruby's native API as exposed through ruby.h and libruby. Ignoring for the moment the fact that this API exposes way more of Ruby's internals than it should, extensions present a very difficult problem for other implementations:&lt;br /&gt;
&lt;br /&gt;
Do we support them or not?&lt;br /&gt;
&lt;br /&gt;
In many cases, this question is answered for us; most extensions require access to object internals we can't expose, or can't expose without extremely expensive copying back and forth. But there's also a silver lining: the vast majority of C-based extensions exist solely to wrap another library.&lt;br /&gt;
&lt;br /&gt;
Isn't it obvious what's needed here?&lt;br /&gt;
&lt;br /&gt;
This problem has been tackled by a number of libraries on a number of platforms. On the JVM, there's Java Native Access (JNA). On Python, there's ctypes. And even on Ruby, there's the &amp;quot;dl&amp;quot; stdlib, wrapping libdl for programmatic access to dynamic libraries. But dl is not widely used, because of real or perceived bugs and a rather arcane API. Something better is needed.&lt;br /&gt;
&lt;br /&gt;
Wayne is one of the primary maintainers of JNA, and has recently spent time on a new higher-performance version of it called JFFI. Wayne also became a JRuby committer this spring, and perhaps his most impressive contribution to date is a full FFI library for JRuby, based on JNA (eventually JFFI, once we migrate fully) and implementing the full set of what we and Evan agreed would be &amp;quot;FFI API 1.0&amp;quot;. We shipped the completed FFI support in JRuby 1.1.4.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;Passwd&amp;quot; and &amp;quot;Group&amp;quot; structures for functions like 'getpwuid':&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module Etc&lt;br /&gt;
  class Passwd &amp;lt; FFI::Struct&lt;br /&gt;
    layout :pw_name, :string, 0,&lt;br /&gt;
           :pw_passwd, :string, 4,&lt;br /&gt;
           :pw_uid, :uint, 8,&lt;br /&gt;
           :pw_gid, :uint, 12,&lt;br /&gt;
           :pw_dir, :string, 20,&lt;br /&gt;
           :pw_shell, :string, 24&lt;br /&gt;
  end&lt;br /&gt;
  class Group &amp;lt; FFI::Struct&lt;br /&gt;
    layout :gr_name, :string, 0,&lt;br /&gt;
           :gr_gid, :uint, 8&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In JRuby 1.1.5, we've taken another step forward with the API, adding support for callbacks. How would we represent a callback you pass into a C function from Ruby?&lt;br /&gt;
&lt;br /&gt;
Binding and calling &amp;quot;qsort&amp;quot; with an array of integers:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'ffi'&lt;br /&gt;
&lt;br /&gt;
module LibC&lt;br /&gt;
  extend FFI::Library&lt;br /&gt;
  callback :qsort_cmp, [ :pointer, :pointer ], :int&lt;br /&gt;
  attach_function :qsort, [ :pointer, :int, :int, :qsort_cmp ], :int&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
p = MemoryPointer.new(:int, 2)&lt;br /&gt;
p.put_array_of_int32(0, [ 2, 1 ])&lt;br /&gt;
puts &amp;quot;Before qsort #{p.get_array_of_int32(0, 2).join(', ')}&amp;quot;&lt;br /&gt;
LibC.qsort(p, 2, 4) do |p1, p2|&lt;br /&gt;
  i1 = p1.get_int32(0)&lt;br /&gt;
  i2 = p2.get_int32(0)&lt;br /&gt;
  i1 &amp;lt; i2 ? -1 : i1 &amp;gt; i2 ? 1 : 0&lt;br /&gt;
end&lt;br /&gt;
puts &amp;quot;After qsort #{p.get_array_of_int32(0, 2).join(', ')}&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What good is having such a library if it doesn't run everywhere? Up until recently, only Rubinius and JRuby supported FFI, which made our case for cross-implementation use pretty weak. Even though we were getting good use out of FFI, there was no motivation for anyone to use it in general, since the standard Ruby implementation had no support.&lt;br /&gt;
&lt;br /&gt;
That is, until Wayne pulled another rabbit out of his hat and implemented FFI for C Ruby as well. The JRuby team is proud to announce a wholly non-JRuby library: FFI is now available on Ruby 1.9 and Ruby 1.8.6/7, in addition to JRuby 1.1.4+ and Rubinius (though Rubinius does not yet support callbacks).&lt;br /&gt;
&lt;br /&gt;
Session showing installation and use of FFI in C Ruby:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ sudo gem install ffi&lt;br /&gt;
Password:&lt;br /&gt;
Building native extensions.  This could take a while...&lt;br /&gt;
Successfully installed ffi-0.1.1&lt;br /&gt;
1 gem installed&lt;br /&gt;
Installing ri documentation for ffi-0.1.1...&lt;br /&gt;
Installing RDoc documentation for ffi-0.1.1...&lt;br /&gt;
[headius @ cnutter:~]&lt;br /&gt;
$ irb&lt;br /&gt;
&amp;gt;&amp;gt; require 'ffi'&lt;br /&gt;
=&amp;gt; true&lt;br /&gt;
&amp;gt;&amp;gt; module RubyFFI&lt;br /&gt;
&amp;gt;&amp;gt; extend FFI::Library&lt;br /&gt;
&amp;gt;&amp;gt; attach_function :getuid, [], :uint&lt;br /&gt;
&amp;gt;&amp;gt; end&lt;br /&gt;
=&amp;gt; #&amp;lt;FFI::Invoker:0x1fe8c&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; puts RubyFFI.getuid&lt;br /&gt;
501&lt;br /&gt;
=&amp;gt; nil&lt;br /&gt;
&amp;gt;&amp;gt; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Our hope with JRuby's support of FFI and our release of FFI for C Ruby is that we may finally escape the hell of C extensions. &lt;br /&gt;
&lt;br /&gt;
A key feature that's not well documented is the use of FFI's templating system to generate bindings based on the current platform's header files. Here's a sample from the &amp;quot;Etc&amp;quot; module above.&lt;br /&gt;
&lt;br /&gt;
Etc module template, showing how to pull in header files and inspect a struct definition:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module Etc&lt;br /&gt;
  class Passwd &amp;lt; FFI::Struct&lt;br /&gt;
    @@@&lt;br /&gt;
    struct do |s|&lt;br /&gt;
      s.include &amp;quot;sys/types.h&amp;quot;&lt;br /&gt;
      s.include &amp;quot;pwd.h&amp;quot;&lt;br /&gt;
&lt;br /&gt;
      s.name &amp;quot;struct passwd&amp;quot;&lt;br /&gt;
      s.field :pw_name, :string&lt;br /&gt;
      s.field :pw_passwd, :string&lt;br /&gt;
      s.field :pw_uid, :uint&lt;br /&gt;
      s.field :pw_gid, :uint&lt;br /&gt;
      s.field :pw_dir, :string&lt;br /&gt;
      s.field :pw_shell, :string&lt;br /&gt;
    end&lt;br /&gt;
    @@@&lt;br /&gt;
  end&lt;br /&gt;
  class Group &amp;lt; FFI::Struct&lt;br /&gt;
    @@@&lt;br /&gt;
    struct do |s|&lt;br /&gt;
      s.include &amp;quot;sys/types.h&amp;quot;&lt;br /&gt;
      s.include &amp;quot;grp.h&amp;quot;&lt;br /&gt;
&lt;br /&gt;
      s.name &amp;quot;struct group&amp;quot;&lt;br /&gt;
      s.field :gr_name, :string&lt;br /&gt;
      s.field :gr_gid, :uint&lt;br /&gt;
    end&lt;br /&gt;
    @@@&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Basic Usage of Ruby-FFI&amp;lt;ref&amp;gt;https://github.com/ffi/ffi/wiki/Basic-Usage&amp;lt;/ref&amp;gt;===&lt;br /&gt;
Before showing the example, we would introduce several FFI's core components&amp;lt;ref&amp;gt;https://github.com/ffi/ffi/wiki/Core-Concepts#wiki-figure-1---overall-ffi-architecture&amp;lt;/ref&amp;gt;. Understanding the following core modules and classes is a great way to start getting FFI's capabilities:&lt;br /&gt;
&lt;br /&gt;
*FFI::Library - along with require 'ffi', this module provides FFI library interfacing capabilities into your Ruby code. Typically you need to extend your custom module with FFI::Library, specify the native libraries and their calling conventions, prototype the native library's functions and structs in Ruby, and then start using the native library's API from Ruby.&lt;br /&gt;
*FFI::Pointer - wraps native memory allocated by a third party library. It provides a number of methods for transferring data from unmanaged native memory to Ruby-managed native memory (FFI::MemoryPointer). The native memory wrapped by this class is not freed during garbage collection runs.&lt;br /&gt;
*FFI::MemoryPointer - allows for Ruby code to allocate native memory and pass it to non-Ruby libraries. Lifecycle management (allocation and deallocation) are handled by this class, so when it gets garbage collected the native memory is also freed.&lt;br /&gt;
*FFI::Struct and FFI::Union&lt;br /&gt;
&lt;br /&gt;
Here is a  &amp;quot;Hello, World&amp;quot; example how to use Ruby-FFI.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'ffi'&lt;br /&gt;
&lt;br /&gt;
module Hello&lt;br /&gt;
  extend FFI::Library&lt;br /&gt;
  ffi_lib FFI::Library::LIBC&lt;br /&gt;
  attach_function :puts, [ :string ], :int&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
Hello.puts(&amp;quot;Hello, World&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The interesting part above is the attach_function call. It requests that a C function named puts which takes a :string argument and returns an :int, be attached to the Hello module.&lt;br /&gt;
&lt;br /&gt;
The attach_function method locates the C function in a specific external library (i.e. libc in the example). The name of the function, the parameter types and the return type are needed. In the above example, attach_function locates a function named puts, which papameter type and return type are :string and :int respectively.&lt;br /&gt;
&lt;br /&gt;
The typical parameter and return types&amp;lt;ref&amp;gt;https://github.com/ffi/ffi/wiki/Types&amp;lt;/ref&amp;gt; are listed here: &lt;br /&gt;
&lt;br /&gt;
* :char and :uchar - 8 bit signed and unsigned values&lt;br /&gt;
* :short and :ushort - 16 bit signed and unsigned values&lt;br /&gt;
* :int and :uint - 32 bit signed and unsigned values&lt;br /&gt;
* :long_long and :ulong_long - 64 bit signed and unsigned values&lt;br /&gt;
* :long and :ulong - native cpu word (32 bit or 64bit) signed and unsigned values. Equivalent to C 'long' type.&lt;br /&gt;
* :float and :double&lt;br /&gt;
* :string - C string, NULL terminated.&lt;br /&gt;
* :pointer - a C pointer&lt;br /&gt;
&lt;br /&gt;
You can also pass the struct as parameter. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
typedef struct _WHAT {&lt;br /&gt;
  int d;&lt;br /&gt;
} WHAT;&lt;br /&gt;
&lt;br /&gt;
int doit(WHAT w) {&lt;br /&gt;
  printf(&amp;quot;%d\n&amp;quot;, w.d);&lt;br /&gt;
  return w.d;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class WHAT &amp;lt; FFI::Struct&lt;br /&gt;
  layout :d, :int&lt;br /&gt;
end&lt;br /&gt;
attach_function 'doit', [ WHAT.by_value ], :int&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above 2 pieces of code, attach_function uses struct WHAT as a parameter type.&lt;br /&gt;
&lt;br /&gt;
===Docs on FFI===&lt;br /&gt;
[http://wiki.jruby.org/wiki/Calling_C_from_JRuby Calling C from JRuby]&amp;lt;br/&amp;gt;&lt;br /&gt;
[http://blog.segment7.net/articles/2008/01/15/rubinius-foreign-function-interfaceRubinius's Foreign Function Interface]&amp;lt;br/&amp;gt;&lt;br /&gt;
[http://pluskid.lifegoo.com/?p=370On the Rubinius FFI]&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Who uses it?==&lt;br /&gt;
The libffi library is useful to anyone trying to build a bridge between interpreted and natively compiled code. Some notable users include:&lt;br /&gt;
*CPython - the default, most-widely used implementation of the Python programming language uses libffi in the standard ctypes library.&lt;br /&gt;
*OpenJDK - the open-source implementation of the Java Platform Standard Edition uses libffi to bridge between the interpreter and native code for some platforms.&lt;br /&gt;
*js-ctypes - a foreign function interface for javascript that Mozilla will be shipping in Firefox 3.6.&lt;br /&gt;
*Dalvik - Dalvik is the virtual machine which runs the Java platform on Android mobile devices. libffi is used on Android ports for which no custom bridging code has been written.&lt;br /&gt;
*Java Native Access (JNA) - the JNI-free way to call native code from Java.&lt;br /&gt;
*Ruby-FFI - a Foreign Function Interface extension for Ruby.&lt;br /&gt;
*fsbv - Foreign Structure By Value is a foreign function interface library for Common Lisp that extends the standard CFFI package to include support for passing structure arguments by value.&lt;br /&gt;
*JSCocoa - call Objective-C code from javascript on Mac OSX and the iPhone (via the libffi-iphone port).&lt;br /&gt;
*PyObjC - call Objective-C code from Python on Mac OSX.&lt;br /&gt;
*RubyCocoa - call Objective-C code from Ruby on Mac OSX.&lt;br /&gt;
*PLT Scheme - call C code from this popular Scheme implementation (also used as the implementation platform for Paul Graham's new Lisp, Arc).&lt;br /&gt;
*gcj - the runtime library for the GNU Compiler for the Java Programming Language uses libffi to handle calls back and forth between interpreted and natively compiled code. gcj is part of the GCC, the GNU Compiler Collection.&lt;br /&gt;
&lt;br /&gt;
==Supported Platforms==&lt;br /&gt;
Libffi has been ported to many different platforms. For specific configuration details and testing status, please refer to the wiki page [http://www.moxielogic.org/wiki/index.php?title=Libffi_3.0.13 here]&lt;br /&gt;
&lt;br /&gt;
==Adoption==&lt;br /&gt;
[http://ruby-doc.org/stdlib-2.0/libdoc/fiddle/rdoc/index.html Fiddle]&amp;lt;br/&amp;gt;&lt;br /&gt;
A libffi wrapper in the Ruby Standard Library&amp;lt;br/&amp;gt;&lt;br /&gt;
[http://github.com/ffi/ffi Ruby-FFI]&amp;lt;br/&amp;gt;&lt;br /&gt;
A Foreign Function Interface extension for Ruby.&amp;lt;br/&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/RubyCocoa  RubyCocoa]&amp;lt;br/&amp;gt;&lt;br /&gt;
Call Objective-C code from Ruby on Mac OSX.&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
http://en.wikipedia.org/wiki/Libffi&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''References''' ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
*http://github.com/atgreen/libffi/blob/master/LICENSE&lt;br /&gt;
*http://repository.readscheme.org/ftp/papers/sw2004/barzilay.pdf&lt;br /&gt;
*http://hg.mozilla.org/mozilla-central/file/2dc00d4b379a/js/ctypes/libffi&lt;br /&gt;
*https://developer.mozilla.org/en/js-ctypes&lt;br /&gt;
*https://developer.mozilla.org/en/js-ctypes/js-ctypes_reference&lt;br /&gt;
*http://blog.headius.com/2008/10/ffi-for-ruby-now-available.html&lt;br /&gt;
*http://www.rubyinside.com/ruby-ffi-library-calling-external-libraries-now-easier-1293.html&lt;br /&gt;
*http://sourceware.org/libffi/&lt;/div&gt;</summary>
		<author><name>Qjia2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1h_jg&amp;diff=83134</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1h jg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1h_jg&amp;diff=83134"/>
		<updated>2014-02-10T21:04:03Z</updated>

		<summary type="html">&lt;p&gt;Qjia2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== '''Ruby libraries to load objects of other languages at run time''' ==&lt;br /&gt;
&lt;br /&gt;
This is an advanced topic. Libraries are being developed where Ruby gems can load libraries (and even native code) of other languages.A few open-source projects like FFI are currently working on this. Previous version is available [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/ch1_1w21_w here]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
==Introduction==&lt;br /&gt;
===Runtime Library===&lt;br /&gt;
In computer programming, a runtime library is the API used by a compiler to invoke some of the behaviors of a runtime system. The runtime system implements the execution model and other fundamental behaviors of a programming language. The compiler inserts calls to the runtime library into the executable binary. During execution (run time) of that computer program, execution of those calls to the runtime library cause communication between the application and the runtime system. This often includes functions for input and output, or for memory management.&lt;br /&gt;
The runtime library may implement a portion of the runtime system's behavior, but if one reads the code of the calls available, they typically are thin wrappers that simply package information and send it to the runtime system. However, sometimes the term runtime library is meant to include the code of the runtime system itself, even though much of that code cannot be directly reached via a library call.&lt;br /&gt;
&lt;br /&gt;
For example, some language features that can be performed only (or are more efficient or accurate) at runtime are implemented in the runtime system and may be invoked via the runtime library API, e.g. some logic errors, array bounds checking, dynamic type checking, exception handling and possibly debugging functionality. For this reason, some programming bugs are not discovered until the program is tested in a &amp;quot;live&amp;quot; environment with real data, despite sophisticated compile-time checking and pre-release testing. In this case, the end user may encounter a runtime error message.&lt;br /&gt;
&lt;br /&gt;
The concept of a runtime library should not be confused with an ordinary program library like that created by an application programmer or delivered by a third party, nor with a dynamic library, meaning a program library linked at run time.&lt;br /&gt;
&lt;br /&gt;
===libffi===&lt;br /&gt;
FFI stands for Foreign Function Interface. A foreign function interface is the popular name for the interface that allows code written in one language to call code written in another language. The libffi was originally written by Anthony Green&amp;lt;ref&amp;gt;http://moxielogic.org/blog&amp;lt;/ref&amp;gt;. The libffi library really only provides the lowest, machine dependent layer of a fully featured foreign function interface. A layer must exist above libffi that handles type conversions for values passed between the two languages.&amp;lt;ref&amp;gt;http://sourceware.org/libffi/&amp;lt;/ref&amp;gt;&lt;br /&gt;
libffi is a foreign function interface library. It provides a C programming language interface for calling natively compiled functions given information about the target function at run time instead of compile time. It also implements the opposite functionality: libffi can produce a pointer to a function that can accept and decode any combination of arguments defined at run time.&lt;br /&gt;
libffi is most often used as a bridging technology between compiled and interpreted language implementations. libffi may also be used to implement plug-ins, where the plug-in's function signatures are not known at the time of creating the host application.&lt;br /&gt;
Notable users include Python, Haskell, Dalvik, F-Script, PyPy, PyObjC, RubyCocoa, JRuby, Rubinius, MacRuby, gcj, GNU Smalltalk, IcedTea, Cycript, Pawn, Squeak, Java Native Access, Racket,&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Libffi#cite_note-2&amp;lt;/ref&amp;gt; Embeddable Common Lisp and Mozilla.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Libffi#cite_note-3&amp;lt;/ref&amp;gt;&lt;br /&gt;
On Mac OS X libffi is commonly used with BridgeSupport, which provides programming language neutral descriptions of framework interfaces, and Nu which binds direct Objective-C access from Lisp.&lt;br /&gt;
libffi has been widely ported and is released under a MIT license.&lt;br /&gt;
&lt;br /&gt;
===Ruby-FFI===&lt;br /&gt;
Ruby-FFI&amp;lt;ref&amp;gt;https://github.com/ffi/ffi/wiki&amp;lt;/ref&amp;gt; is a Foreign Function Interface extension for Ruby. It is an FFI extension doesn't need compilation and can be used on multi-platform and multi-implementation. Ruby-FFI extension is easy to read,write and maintain. In addition, it is impervious to changes in the internal Ruby API.&lt;br /&gt;
&lt;br /&gt;
==How does it work?&amp;lt;ref&amp;gt;http://www.rubyinside.com/ruby-ffi-library-calling-external-libraries-now-easier-1293.html&amp;lt;/ref&amp;gt;==&lt;br /&gt;
The many compiled bridges between external libraries and Ruby pose a problem for alternate implementations like JRuby, because of the complexity involved in exposing internals of the implementation or expensive serialization in both directions. Instead, an interface is necessary so that instead of developing libraries that act only as unique bridges to others, we can just have one library that provides the interface to any arbitrary library of our choice.&lt;br /&gt;
&lt;br /&gt;
Ruby already has a library called &amp;quot;dl&amp;quot; that makes it possible to dynamically link external libraries with Ruby. It's a bit arcane though, and Charles points out that it's not widely used &amp;quot;because of real or perceived bugs.&amp;quot; Given this, and given the need for an implementation that can be compatible with JRuby, Wayne Meissner has developed &amp;quot;FFI&amp;quot;, a new Ruby library that provides &amp;quot;Foreign Function Interface&amp;quot; features to Ruby.&lt;br /&gt;
===Progress of FFI&amp;lt;ref&amp;gt;http://blog.headius.com/2008/10/ffi-for-ruby-now-available.html&amp;lt;/ref&amp;gt;===&lt;br /&gt;
One of the largest problems plaguing Ruby implementations is the ever-painful story of &amp;quot;extensions&amp;quot;. In general, these take the form of a dynamic library, usually written in C, that plugs into and calls Ruby's native API as exposed through ruby.h and libruby. Ignoring for the moment the fact that this API exposes way more of Ruby's internals than it should, extensions present a very difficult problem for other implementations:&lt;br /&gt;
&lt;br /&gt;
Do we support them or not?&lt;br /&gt;
&lt;br /&gt;
In many cases, this question is answered for us; most extensions require access to object internals we can't expose, or can't expose without extremely expensive copying back and forth. But there's also a silver lining: the vast majority of C-based extensions exist solely to wrap another library.&lt;br /&gt;
&lt;br /&gt;
Isn't it obvious what's needed here?&lt;br /&gt;
&lt;br /&gt;
This problem has been tackled by a number of libraries on a number of platforms. On the JVM, there's Java Native Access (JNA). On Python, there's ctypes. And even on Ruby, there's the &amp;quot;dl&amp;quot; stdlib, wrapping libdl for programmatic access to dynamic libraries. But dl is not widely used, because of real or perceived bugs and a rather arcane API. Something better is needed.&lt;br /&gt;
&lt;br /&gt;
Wayne is one of the primary maintainers of JNA, and has recently spent time on a new higher-performance version of it called JFFI. Wayne also became a JRuby committer this spring, and perhaps his most impressive contribution to date is a full FFI library for JRuby, based on JNA (eventually JFFI, once we migrate fully) and implementing the full set of what we and Evan agreed would be &amp;quot;FFI API 1.0&amp;quot;. We shipped the completed FFI support in JRuby 1.1.4.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;Passwd&amp;quot; and &amp;quot;Group&amp;quot; structures for functions like 'getpwuid':&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module Etc&lt;br /&gt;
  class Passwd &amp;lt; FFI::Struct&lt;br /&gt;
    layout :pw_name, :string, 0,&lt;br /&gt;
           :pw_passwd, :string, 4,&lt;br /&gt;
           :pw_uid, :uint, 8,&lt;br /&gt;
           :pw_gid, :uint, 12,&lt;br /&gt;
           :pw_dir, :string, 20,&lt;br /&gt;
           :pw_shell, :string, 24&lt;br /&gt;
  end&lt;br /&gt;
  class Group &amp;lt; FFI::Struct&lt;br /&gt;
    layout :gr_name, :string, 0,&lt;br /&gt;
           :gr_gid, :uint, 8&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In JRuby 1.1.5, we've taken another step forward with the API, adding support for callbacks. How would we represent a callback you pass into a C function from Ruby?&lt;br /&gt;
&lt;br /&gt;
Binding and calling &amp;quot;qsort&amp;quot; with an array of integers:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'ffi'&lt;br /&gt;
&lt;br /&gt;
module LibC&lt;br /&gt;
  extend FFI::Library&lt;br /&gt;
  callback :qsort_cmp, [ :pointer, :pointer ], :int&lt;br /&gt;
  attach_function :qsort, [ :pointer, :int, :int, :qsort_cmp ], :int&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
p = MemoryPointer.new(:int, 2)&lt;br /&gt;
p.put_array_of_int32(0, [ 2, 1 ])&lt;br /&gt;
puts &amp;quot;Before qsort #{p.get_array_of_int32(0, 2).join(', ')}&amp;quot;&lt;br /&gt;
LibC.qsort(p, 2, 4) do |p1, p2|&lt;br /&gt;
  i1 = p1.get_int32(0)&lt;br /&gt;
  i2 = p2.get_int32(0)&lt;br /&gt;
  i1 &amp;lt; i2 ? -1 : i1 &amp;gt; i2 ? 1 : 0&lt;br /&gt;
end&lt;br /&gt;
puts &amp;quot;After qsort #{p.get_array_of_int32(0, 2).join(', ')}&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What good is having such a library if it doesn't run everywhere? Up until recently, only Rubinius and JRuby supported FFI, which made our case for cross-implementation use pretty weak. Even though we were getting good use out of FFI, there was no motivation for anyone to use it in general, since the standard Ruby implementation had no support.&lt;br /&gt;
&lt;br /&gt;
That is, until Wayne pulled another rabbit out of his hat and implemented FFI for C Ruby as well. The JRuby team is proud to announce a wholly non-JRuby library: FFI is now available on Ruby 1.9 and Ruby 1.8.6/7, in addition to JRuby 1.1.4+ and Rubinius (though Rubinius does not yet support callbacks).&lt;br /&gt;
&lt;br /&gt;
Session showing installation and use of FFI in C Ruby:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ sudo gem install ffi&lt;br /&gt;
Password:&lt;br /&gt;
Building native extensions.  This could take a while...&lt;br /&gt;
Successfully installed ffi-0.1.1&lt;br /&gt;
1 gem installed&lt;br /&gt;
Installing ri documentation for ffi-0.1.1...&lt;br /&gt;
Installing RDoc documentation for ffi-0.1.1...&lt;br /&gt;
[headius @ cnutter:~]&lt;br /&gt;
$ irb&lt;br /&gt;
&amp;gt;&amp;gt; require 'ffi'&lt;br /&gt;
=&amp;gt; true&lt;br /&gt;
&amp;gt;&amp;gt; module RubyFFI&lt;br /&gt;
&amp;gt;&amp;gt; extend FFI::Library&lt;br /&gt;
&amp;gt;&amp;gt; attach_function :getuid, [], :uint&lt;br /&gt;
&amp;gt;&amp;gt; end&lt;br /&gt;
=&amp;gt; #&amp;lt;FFI::Invoker:0x1fe8c&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; puts RubyFFI.getuid&lt;br /&gt;
501&lt;br /&gt;
=&amp;gt; nil&lt;br /&gt;
&amp;gt;&amp;gt; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Our hope with JRuby's support of FFI and our release of FFI for C Ruby is that we may finally escape the hell of C extensions. &lt;br /&gt;
&lt;br /&gt;
A key feature that's not well documented is the use of FFI's templating system to generate bindings based on the current platform's header files. Here's a sample from the &amp;quot;Etc&amp;quot; module above.&lt;br /&gt;
&lt;br /&gt;
Etc module template, showing how to pull in header files and inspect a struct definition:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module Etc&lt;br /&gt;
  class Passwd &amp;lt; FFI::Struct&lt;br /&gt;
    @@@&lt;br /&gt;
    struct do |s|&lt;br /&gt;
      s.include &amp;quot;sys/types.h&amp;quot;&lt;br /&gt;
      s.include &amp;quot;pwd.h&amp;quot;&lt;br /&gt;
&lt;br /&gt;
      s.name &amp;quot;struct passwd&amp;quot;&lt;br /&gt;
      s.field :pw_name, :string&lt;br /&gt;
      s.field :pw_passwd, :string&lt;br /&gt;
      s.field :pw_uid, :uint&lt;br /&gt;
      s.field :pw_gid, :uint&lt;br /&gt;
      s.field :pw_dir, :string&lt;br /&gt;
      s.field :pw_shell, :string&lt;br /&gt;
    end&lt;br /&gt;
    @@@&lt;br /&gt;
  end&lt;br /&gt;
  class Group &amp;lt; FFI::Struct&lt;br /&gt;
    @@@&lt;br /&gt;
    struct do |s|&lt;br /&gt;
      s.include &amp;quot;sys/types.h&amp;quot;&lt;br /&gt;
      s.include &amp;quot;grp.h&amp;quot;&lt;br /&gt;
&lt;br /&gt;
      s.name &amp;quot;struct group&amp;quot;&lt;br /&gt;
      s.field :gr_name, :string&lt;br /&gt;
      s.field :gr_gid, :uint&lt;br /&gt;
    end&lt;br /&gt;
    @@@&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Basic Usage of Ruby-FFI&amp;lt;ref&amp;gt;https://github.com/ffi/ffi/wiki/Basic-Usage&amp;lt;/ref&amp;gt;===&lt;br /&gt;
Before showing the example, we would introduce several FFI's core components&amp;lt;ref&amp;gt;https://github.com/ffi/ffi/wiki/Core-Concepts#wiki-figure-1---overall-ffi-architecture&amp;lt;/ref&amp;gt;. Understanding the following core modules and classes is a great way to start getting FFI's capabilities:&lt;br /&gt;
&lt;br /&gt;
*FFI::Library - along with require 'ffi', this module provides FFI library interfacing capabilities into your Ruby code. Typically you need to extend your custom module with FFI::Library, specify the native libraries and their calling conventions, prototype the native library's functions and structs in Ruby, and then start using the native library's API from Ruby.&lt;br /&gt;
*FFI::Pointer - wraps native memory allocated by a third party library. It provides a number of methods for transferring data from unmanaged native memory to Ruby-managed native memory (FFI::MemoryPointer). The native memory wrapped by this class is not freed during garbage collection runs.&lt;br /&gt;
*FFI::MemoryPointer - allows for Ruby code to allocate native memory and pass it to non-Ruby libraries. Lifecycle management (allocation and deallocation) are handled by this class, so when it gets garbage collected the native memory is also freed.&lt;br /&gt;
*FFI::Struct and FFI::Union&lt;br /&gt;
&lt;br /&gt;
Here is a  &amp;quot;Hello, World&amp;quot; example how to use Ruby-FFI.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'ffi'&lt;br /&gt;
&lt;br /&gt;
module Hello&lt;br /&gt;
  extend FFI::Library&lt;br /&gt;
  ffi_lib FFI::Library::LIBC&lt;br /&gt;
  attach_function :puts, [ :string ], :int&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
Hello.puts(&amp;quot;Hello, World&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The interesting part above is the attach_function call. It requests that a C function named puts which takes a :string argument and returns an :int, be attached to the Hello module.&lt;br /&gt;
&lt;br /&gt;
The attach_function method locates the C function in a specific external library (i.e. libc in the example). The name of the function, the parameter types and the return type are needed. In the above example, attach_function locates a function named puts, which papameter type and return type are :string and :int respectively.&lt;br /&gt;
&lt;br /&gt;
The typical parameter and return types&amp;lt;ref&amp;gt;https://github.com/ffi/ffi/wiki/Types&amp;lt;/ref&amp;gt; are listed here: &lt;br /&gt;
&lt;br /&gt;
* :char and :uchar - 8 bit signed and unsigned values&lt;br /&gt;
* :short and :ushort - 16 bit signed and unsigned values&lt;br /&gt;
* :int and :uint - 32 bit signed and unsigned values&lt;br /&gt;
* :long_long and :ulong_long - 64 bit signed and unsigned values&lt;br /&gt;
* :long and :ulong - native cpu word (32 bit or 64bit) signed and unsigned values. Equivalent to C 'long' type.&lt;br /&gt;
* :float and :double&lt;br /&gt;
* :string - C string, NULL terminated.&lt;br /&gt;
* :pointer - a C pointer&lt;br /&gt;
&lt;br /&gt;
You can also pass the struct as parameter. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
typedef struct _WHAT {&lt;br /&gt;
  int d;&lt;br /&gt;
} WHAT;&lt;br /&gt;
&lt;br /&gt;
int doit(WHAT w) {&lt;br /&gt;
  printf(&amp;quot;%d\n&amp;quot;, w.d);&lt;br /&gt;
  return w.d;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class WHAT &amp;lt; FFI::Struct&lt;br /&gt;
  layout :d, :int&lt;br /&gt;
end&lt;br /&gt;
attach_function 'doit', [ WHAT.by_value ], :int&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above 2 pieces of code, attach_function uses struct WHAT as a parameter type.&lt;br /&gt;
&lt;br /&gt;
===Docs on FFI===&lt;br /&gt;
[http://wiki.jruby.org/wiki/Calling_C_from_JRuby Calling C from JRuby]&amp;lt;br/&amp;gt;&lt;br /&gt;
[http://blog.segment7.net/articles/2008/01/15/rubinius-foreign-function-interfaceRubinius's Foreign Function Interface]&amp;lt;br/&amp;gt;&lt;br /&gt;
[http://pluskid.lifegoo.com/?p=370On the Rubinius FFI]&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Who uses it?==&lt;br /&gt;
The libffi library is useful to anyone trying to build a bridge between interpreted and natively compiled code. Some notable users include:&lt;br /&gt;
*CPython - the default, most-widely used implementation of the Python programming language uses libffi in the standard ctypes library.&lt;br /&gt;
*OpenJDK - the open-source implementation of the Java Platform Standard Edition uses libffi to bridge between the interpreter and native code for some platforms.&lt;br /&gt;
*js-ctypes - a foreign function interface for javascript that Mozilla will be shipping in Firefox 3.6.&lt;br /&gt;
*Dalvik - Dalvik is the virtual machine which runs the Java platform on Android mobile devices. libffi is used on Android ports for which no custom bridging code has been written.&lt;br /&gt;
*Java Native Access (JNA) - the JNI-free way to call native code from Java.&lt;br /&gt;
*Ruby-FFI - a Foreign Function Interface extension for Ruby.&lt;br /&gt;
*fsbv - Foreign Structure By Value is a foreign function interface library for Common Lisp that extends the standard CFFI package to include support for passing structure arguments by value.&lt;br /&gt;
*JSCocoa - call Objective-C code from javascript on Mac OSX and the iPhone (via the libffi-iphone port).&lt;br /&gt;
*PyObjC - call Objective-C code from Python on Mac OSX.&lt;br /&gt;
*RubyCocoa - call Objective-C code from Ruby on Mac OSX.&lt;br /&gt;
*PLT Scheme - call C code from this popular Scheme implementation (also used as the implementation platform for Paul Graham's new Lisp, Arc).&lt;br /&gt;
*gcj - the runtime library for the GNU Compiler for the Java Programming Language uses libffi to handle calls back and forth between interpreted and natively compiled code. gcj is part of the GCC, the GNU Compiler Collection.&lt;br /&gt;
&lt;br /&gt;
==Supported Platforms==&lt;br /&gt;
Libffi has been ported to many different platforms. For specific configuration details and testing status, please refer to the wiki page [http://www.moxielogic.org/wiki/index.php?title=Libffi_3.0.13 here]&lt;br /&gt;
&lt;br /&gt;
==Adoption==&lt;br /&gt;
[http://ruby-doc.org/stdlib-2.0/libdoc/fiddle/rdoc/index.html Fiddle]&amp;lt;br/&amp;gt;&lt;br /&gt;
A libffi wrapper in the Ruby Standard Library&amp;lt;br/&amp;gt;&lt;br /&gt;
[http://github.com/ffi/ffi Ruby-FFI]&amp;lt;br/&amp;gt;&lt;br /&gt;
A Foreign Function Interface extension for Ruby.&amp;lt;br/&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/RubyCocoa  RubyCocoa]&amp;lt;br/&amp;gt;&lt;br /&gt;
Call Objective-C code from Ruby on Mac OSX.&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
http://en.wikipedia.org/wiki/Libffi&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''References''' ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
*http://github.com/atgreen/libffi/blob/master/LICENSE&lt;br /&gt;
*http://repository.readscheme.org/ftp/papers/sw2004/barzilay.pdf&lt;br /&gt;
*http://hg.mozilla.org/mozilla-central/file/2dc00d4b379a/js/ctypes/libffi&lt;br /&gt;
*https://developer.mozilla.org/en/js-ctypes&lt;br /&gt;
*https://developer.mozilla.org/en/js-ctypes/js-ctypes_reference&lt;br /&gt;
*http://blog.headius.com/2008/10/ffi-for-ruby-now-available.html&lt;br /&gt;
*http://www.rubyinside.com/ruby-ffi-library-calling-external-libraries-now-easier-1293.html&lt;br /&gt;
*http://sourceware.org/libffi/&lt;/div&gt;</summary>
		<author><name>Qjia2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1h_jg&amp;diff=82947</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1h jg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1h_jg&amp;diff=82947"/>
		<updated>2014-02-04T22:51:42Z</updated>

		<summary type="html">&lt;p&gt;Qjia2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== '''Ruby libraries to load objects of other languages at run time''' ==&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby] is a dynamic, reflective, object-oriented, general-purpose programming language. It is easy to extend Ruby with new features by writing code in Ruby. But every now and then extending ruby with low-level languages, such as[http://en.wikipedia.org/wiki/C_(programming_language) C]/[http://en.wikipedia.org/wiki/C%2B%2B C++]/[http://en.wikipedia.org/wiki/Java_(programming_language) Java] is also necessary.&lt;br /&gt;
&lt;br /&gt;
Currently, various kinds of languages codes could be invoked from within ruby. The extension for C/C++ and Java are focused here.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== '''Ruby C/C++ extensions&amp;lt;ref&amp;gt;http://java.ociweb.com/mark/NFJS/RubyCExtensions.pdf&amp;lt;/ref&amp;gt;''' ==&lt;br /&gt;
By extending Ruby with C. The C libraries could be used directly in Ruby applications.&lt;br /&gt;
Ruby could call C codes in three ways: interpreter API, RubyInline, SWIG.&lt;br /&gt;
=== interpreter API ===&lt;br /&gt;
Ruby interpreter is implemented in C, its API can be used and no special API added for interacting with C like Java’s JNI is needed.&lt;br /&gt;
&lt;br /&gt;
The files needed include:&lt;br /&gt;
*'''extconf.rb'''&lt;br /&gt;
Used to generate Makefile&lt;br /&gt;
&lt;br /&gt;
Platform-specific Makefiles for compiling C extensions to Ruby is needed to be generated firstly.&lt;br /&gt;
&lt;br /&gt;
A simple sample is like below:&lt;br /&gt;
&lt;br /&gt;
create a file containing the following,&lt;br /&gt;
named extconf.rb by convention&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'mkmf'&lt;br /&gt;
extension_name = 'name'&lt;br /&gt;
dir_config(extension_name)&lt;br /&gt;
create_makefile(extension_name)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
And use by running&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ruby extconf.rb&lt;br /&gt;
make&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then generates&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
.so under UNIX/Linux&lt;br /&gt;
.so under Windows when building with Cygwin&lt;br /&gt;
.bundle under Mac OS X&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''C File'''&lt;br /&gt;
C codes to be invoked from Ruby&lt;br /&gt;
&lt;br /&gt;
An example Hello.c is shown below&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#include &amp;lt;ruby.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
// These C functions will be associated with&lt;br /&gt;
// methods of a Ruby class on the next page.&lt;br /&gt;
static VALUE hello(VALUE self, VALUE arg) {&lt;br /&gt;
 char* name = RSTRING(arg)-&amp;gt;ptr;&lt;br /&gt;
 printf(&amp;quot;Hello %s!\n&amp;quot;, name);&lt;br /&gt;
 return Qnil;&lt;br /&gt;
}&lt;br /&gt;
static VALUE goodbye(VALUE class) {&lt;br /&gt;
 printf(&amp;quot;Later dude!\n&amp;quot;);&lt;br /&gt;
 return Qnil;&lt;br /&gt;
}&lt;br /&gt;
// This is called when the Ruby interpreter loads this C extension.&lt;br /&gt;
// The part after &amp;quot;Init_&amp;quot; is the name of the C extension specified&lt;br /&gt;
// in extconf.rb, not the name of the C source file.&lt;br /&gt;
void Init_hello() {&lt;br /&gt;
 // Create a Ruby module.&lt;br /&gt;
 VALUE myModule = rb_define_module(&amp;quot;MyModule&amp;quot;);&lt;br /&gt;
 // Create a Ruby class in this module.&lt;br /&gt;
 // rb_cObject is defined in ruby.h&lt;br /&gt;
 VALUE myClass =&lt;br /&gt;
 rb_define_class_under(myModule, &amp;quot;MyClass&amp;quot;, rb_cObject);&lt;br /&gt;
 // Add an instance method to the Ruby class.&lt;br /&gt;
 int arg_count = 1;&lt;br /&gt;
 rb_define_method(myClass, &amp;quot;hello&amp;quot;, hello, arg_count);&lt;br /&gt;
 // Add a class method to the Ruby class.&lt;br /&gt;
 arg_count = 0;&lt;br /&gt;
 rb_define_module_function(myClass, &amp;quot;goodbye&amp;quot;, goodbye, arg_count);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*'''Ruby File'''&lt;br /&gt;
Ruby code that invokes C code&lt;br /&gt;
&lt;br /&gt;
An example client.rb is shown as below&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'hello'&lt;br /&gt;
include MyModule # so MyClass doesn't need MyModule:: prefix&lt;br /&gt;
obj = MyClass.new # MyClass is defined in C&lt;br /&gt;
obj.hello('Mark') # calling an object method&lt;br /&gt;
MyClass.goodbye # calling a class method&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally we could build and run&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ruby extconf.rb&lt;br /&gt;
make&lt;br /&gt;
ruby client.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then the output will display as&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Hello Mark!&lt;br /&gt;
Later dude!&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== RubyInline ===&lt;br /&gt;
[http://www.zenspider.com/ZSS/Products/RubyInline/ RubyInline] allows C code to be imbedded in Ruby code. It automatically determines if the code in question has changed and builds it only when necessary. The extensions are then automatically loaded into the class/module that defines it.&lt;br /&gt;
&lt;br /&gt;
To setup RubyInline, just use&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem install rubyinline&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SWIG ===&lt;br /&gt;
[http://en.wikipedia.org/wiki/SWIG SWIG] is a software development tool that connects programs written in C and C++ with a variety of high-level programming languages. SWIG is used with different types of target languages including common scripting languages such as Perl, PHP, Python, Tcl and Ruby. &lt;br /&gt;
&lt;br /&gt;
As an example, building Ruby Extensions under Windows 95/NT is shown as below&lt;br /&gt;
Building a SWIG extension to Ruby under Windows 95/NT is roughly similar to the process used with Unix. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
C:\swigtest&amp;gt; ruby extconf.rb&lt;br /&gt;
C:\swigtest&amp;gt; nmake&lt;br /&gt;
C:\swigtest&amp;gt; nmake install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== '''Ruby JAVA extensions''' ==&lt;br /&gt;
To extend Ruby with JAVA, the [http://jruby.org/ JRuby] is a good tool to use. JRuby is a high performance, stable, fully threaded Java implementation of the Ruby programming language. It is a Ruby interpreter written entirely in Java and can use Java capabilities from Ruby as well as can use Ruby capabilities from Java.&lt;br /&gt;
=== Using JRuby From Command-Line ===&lt;br /&gt;
*'''Steps to install'''&lt;br /&gt;
– download a binary release [http://jruby.org/ here]&lt;br /&gt;
&lt;br /&gt;
– unzip/untar the downloaded archive&lt;br /&gt;
&lt;br /&gt;
– set JRUBY_HOME environment variable to point to resulting directory&lt;br /&gt;
&lt;br /&gt;
– add $JRUBY_HOME/bin to PATH&lt;br /&gt;
*'''Steps to use'''&lt;br /&gt;
– jruby {script-name}&lt;br /&gt;
*'''Example'''&lt;br /&gt;
– hello.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
name = ARGV[0] || &amp;quot;you&amp;quot;&lt;br /&gt;
puts &amp;quot;Hello #{name}!&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
– run with&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
jruby hello.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
outputs&lt;br /&gt;
&amp;lt;pre&amp;gt; &lt;br /&gt;
Hello you!&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
– run with&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
jruby hello.rb Mark&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
outputs &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Hello Mark&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Using JAVA Classes in JRuby ===&lt;br /&gt;
To use java classes in JRuby, the program must require 'java'&lt;br /&gt;
&lt;br /&gt;
There several options to provide full names of Java classes to be used in JRuby&lt;br /&gt;
*'''option #1''' &lt;br /&gt;
provide full name when using&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
frame = javax.swing.JFrame.new('My Title')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*'''option #2''' &lt;br /&gt;
assign full class name to a constant &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
JFrame = javax.swing.JFrame&lt;br /&gt;
frame = JFrame.new('My Title')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*'''option #3'''&lt;br /&gt;
use include_class&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
include_class 'javax.swing.JFrame'&lt;br /&gt;
frame = JFrame.new('My Title')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*'''option #4'''&lt;br /&gt;
use include_class with an alias&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
include_class('java.lang.String') do |pkg_name, class_name|&lt;br /&gt;
 &amp;quot;J#{class_name}&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
msg = JString.new('My Message')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*'''option #5'''&lt;br /&gt;
use include_package&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module Swing&lt;br /&gt;
 include_package 'javax.swing'&lt;br /&gt;
end&lt;br /&gt;
frame = Swing::JFrame.new('My Title')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
== '''Summary''' ==&lt;br /&gt;
&lt;br /&gt;
== '''See Also''' ==&lt;br /&gt;
*http://java.ociweb.com/mark/NFJS/JRuby.pdf&lt;br /&gt;
*http://java.ociweb.com/mark/NFJS/RubyCExtensions.pdf&lt;br /&gt;
*http://www.swig.org/&lt;br /&gt;
*http://www.zenspider.com/ZSS/Products/RubyInline/&lt;br /&gt;
*http://en.wikibooks.org/wiki/Ruby_Programming/C_Extensions&lt;br /&gt;
&lt;br /&gt;
== '''References''' ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Qjia2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1h_jg&amp;diff=82946</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1h jg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1h_jg&amp;diff=82946"/>
		<updated>2014-02-04T22:51:11Z</updated>

		<summary type="html">&lt;p&gt;Qjia2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== '''Ruby libraries to load objects of other languages at run time''' ==&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby] is a dynamic, reflective, object-oriented, general-purpose programming language. It is easy to extend Ruby with new features by writing code in Ruby. But every now and then extending ruby with low-level languages, such as[http://en.wikipedia.org/wiki/C_(programming_language) C]/[http://en.wikipedia.org/wiki/C%2B%2B C++]/[http://en.wikipedia.org/wiki/Java_(programming_language) Java] is also necessary.&lt;br /&gt;
&lt;br /&gt;
Currently, various kinds of languages codes could be invoked from within ruby. The extension for C/C++ and Java are focused here.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== '''Ruby C/C++ extensions&amp;lt;ref&amp;gt;http://java.ociweb.com/mark/NFJS/RubyCExtensions.pdf&amp;lt;/ref&amp;gt;''' ==&lt;br /&gt;
By extending Ruby with C. The C libraries could be used directly in Ruby applications.&lt;br /&gt;
Ruby could call C codes in three ways: interpreter API, RubyInline, SWIG.&lt;br /&gt;
=== interpreter API ===&lt;br /&gt;
Ruby interpreter is implemented in C, its API can be used and no special API added for interacting with C like Java’s JNI is needed.&lt;br /&gt;
&lt;br /&gt;
The files needed include:&lt;br /&gt;
*'''extconf.rb'''&lt;br /&gt;
Used to generate Makefile&lt;br /&gt;
&lt;br /&gt;
Platform-specific Makefiles for compiling C extensions to Ruby is needed to be generated firstly.&lt;br /&gt;
&lt;br /&gt;
A simple sample is like below:&lt;br /&gt;
&lt;br /&gt;
create a file containing the following,&lt;br /&gt;
named extconf.rb by convention&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'mkmf'&lt;br /&gt;
extension_name = 'name'&lt;br /&gt;
dir_config(extension_name)&lt;br /&gt;
create_makefile(extension_name)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
And use by running&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ruby extconf.rb&lt;br /&gt;
make&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then generates&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
.so under UNIX/Linux&lt;br /&gt;
.so under Windows when building with Cygwin&lt;br /&gt;
.bundle under Mac OS X&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''C File'''&lt;br /&gt;
C codes to be invoked from Ruby&lt;br /&gt;
&lt;br /&gt;
An example Hello.c is shown below&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#include &amp;lt;ruby.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
// These C functions will be associated with&lt;br /&gt;
// methods of a Ruby class on the next page.&lt;br /&gt;
static VALUE hello(VALUE self, VALUE arg) {&lt;br /&gt;
 char* name = RSTRING(arg)-&amp;gt;ptr;&lt;br /&gt;
 printf(&amp;quot;Hello %s!\n&amp;quot;, name);&lt;br /&gt;
 return Qnil;&lt;br /&gt;
}&lt;br /&gt;
static VALUE goodbye(VALUE class) {&lt;br /&gt;
 printf(&amp;quot;Later dude!\n&amp;quot;);&lt;br /&gt;
 return Qnil;&lt;br /&gt;
}&lt;br /&gt;
// This is called when the Ruby interpreter loads this C extension.&lt;br /&gt;
// The part after &amp;quot;Init_&amp;quot; is the name of the C extension specified&lt;br /&gt;
// in extconf.rb, not the name of the C source file.&lt;br /&gt;
void Init_hello() {&lt;br /&gt;
 // Create a Ruby module.&lt;br /&gt;
 VALUE myModule = rb_define_module(&amp;quot;MyModule&amp;quot;);&lt;br /&gt;
 // Create a Ruby class in this module.&lt;br /&gt;
 // rb_cObject is defined in ruby.h&lt;br /&gt;
 VALUE myClass =&lt;br /&gt;
 rb_define_class_under(myModule, &amp;quot;MyClass&amp;quot;, rb_cObject);&lt;br /&gt;
 // Add an instance method to the Ruby class.&lt;br /&gt;
 int arg_count = 1;&lt;br /&gt;
 rb_define_method(myClass, &amp;quot;hello&amp;quot;, hello, arg_count);&lt;br /&gt;
 // Add a class method to the Ruby class.&lt;br /&gt;
 arg_count = 0;&lt;br /&gt;
 rb_define_module_function(myClass, &amp;quot;goodbye&amp;quot;, goodbye, arg_count);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*'''Ruby File'''&lt;br /&gt;
Ruby code that invokes C code&lt;br /&gt;
&lt;br /&gt;
An example client.rb is shown as below&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'hello'&lt;br /&gt;
include MyModule # so MyClass doesn't need MyModule:: prefix&lt;br /&gt;
obj = MyClass.new # MyClass is defined in C&lt;br /&gt;
obj.hello('Mark') # calling an object method&lt;br /&gt;
MyClass.goodbye # calling a class method&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally we could build and run&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ruby extconf.rb&lt;br /&gt;
make&lt;br /&gt;
ruby client.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then the output will display as&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Hello Mark!&lt;br /&gt;
Later dude!&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== RubyInline ===&lt;br /&gt;
[http://www.zenspider.com/ZSS/Products/RubyInline/ RubyInline] allows C code to be imbedded in Ruby code. It automatically determines if the code in question has changed and builds it only when necessary. The extensions are then automatically loaded into the class/module that defines it.&lt;br /&gt;
&lt;br /&gt;
To setup RubyInline, just use&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem install rubyinline&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SWIG ===&lt;br /&gt;
[http://en.wikipedia.org/wiki/SWIG SWIG] is a software development tool that connects programs written in C and C++ with a variety of high-level programming languages. SWIG is used with different types of target languages including common scripting languages such as Perl, PHP, Python, Tcl and Ruby. &lt;br /&gt;
&lt;br /&gt;
As an example, building Ruby Extensions under Windows 95/NT is shown as below&lt;br /&gt;
Building a SWIG extension to Ruby under Windows 95/NT is roughly similar to the process used with Unix. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
C:\swigtest&amp;gt; ruby extconf.rb&lt;br /&gt;
C:\swigtest&amp;gt; nmake&lt;br /&gt;
C:\swigtest&amp;gt; nmake install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== '''Ruby JAVA extensions''' ==&lt;br /&gt;
To extend Ruby with JAVA, the [http://jruby.org/ JRuby] is a good tool to use. JRuby is a high performance, stable, fully threaded Java implementation of the Ruby programming language. It is a Ruby interpreter written entirely in Java and can use Java capabilities from Ruby as well as can use Ruby capabilities from Java.&lt;br /&gt;
=== Using JRuby From Command-Line ===&lt;br /&gt;
*'''Steps to install'''&lt;br /&gt;
– download a binary release [http://jruby.org/ here]&lt;br /&gt;
&lt;br /&gt;
– unzip/untar the downloaded archive&lt;br /&gt;
&lt;br /&gt;
– set JRUBY_HOME environment variable to point to resulting directory&lt;br /&gt;
&lt;br /&gt;
– add $JRUBY_HOME/bin to PATH&lt;br /&gt;
*'''Steps to use'''&lt;br /&gt;
– jruby {script-name}&lt;br /&gt;
*'''Example'''&lt;br /&gt;
– hello.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
name = ARGV[0] || &amp;quot;you&amp;quot;&lt;br /&gt;
puts &amp;quot;Hello #{name}!&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
– run with&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
jruby hello.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
outputs&lt;br /&gt;
&amp;lt;pre&amp;gt; &lt;br /&gt;
Hello you!&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
– run with&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
jruby hello.rb Mark&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
outputs &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Hello Mark&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Using JAVA Classes in JRuby ===&lt;br /&gt;
To use java classes in JRuby, the program must require 'java'&lt;br /&gt;
&lt;br /&gt;
There several options to provide full names of Java classes to be used in JRuby&lt;br /&gt;
*'''option #1''' &lt;br /&gt;
provide full name when using&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
frame = javax.swing.JFrame.new('My Title')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*'''option #2''' &lt;br /&gt;
assign full class name to a constant &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
JFrame = javax.swing.JFrame&lt;br /&gt;
frame = JFrame.new('My Title')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*'''option #3'''&lt;br /&gt;
use include_class&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
include_class 'javax.swing.JFrame'&lt;br /&gt;
frame = JFrame.new('My Title')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*'''option #4'''&lt;br /&gt;
use include_class with an alias&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
include_class('java.lang.String') do |pkg_name, class_name|&lt;br /&gt;
 &amp;quot;J#{class_name}&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
msg = JString.new('My Message')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*'''option #5'''&lt;br /&gt;
use include_package&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module Swing&lt;br /&gt;
 include_package 'javax.swing'&lt;br /&gt;
end&lt;br /&gt;
frame = Swing::JFrame.new('My Title')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== '''See Also''' ==&lt;br /&gt;
*http://java.ociweb.com/mark/NFJS/JRuby.pdf&lt;br /&gt;
*http://java.ociweb.com/mark/NFJS/RubyCExtensions.pdf&lt;br /&gt;
*http://www.swig.org/&lt;br /&gt;
*http://www.zenspider.com/ZSS/Products/RubyInline/&lt;br /&gt;
*http://en.wikibooks.org/wiki/Ruby_Programming/C_Extensions&lt;br /&gt;
&lt;br /&gt;
== '''References''' ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Qjia2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1h_jg&amp;diff=82945</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1h jg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1h_jg&amp;diff=82945"/>
		<updated>2014-02-04T22:48:10Z</updated>

		<summary type="html">&lt;p&gt;Qjia2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== '''Ruby libraries to load objects of other languages at run time''' ==&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby] is a dynamic, reflective, object-oriented, general-purpose programming language. It is easy to extend Ruby with new features by writing code in Ruby. But every now and then extending ruby with low-level languages, such as[http://en.wikipedia.org/wiki/C_(programming_language) C]/[http://en.wikipedia.org/wiki/C%2B%2B C++]/[http://en.wikipedia.org/wiki/Java_(programming_language) Java] is also necessary.&lt;br /&gt;
&lt;br /&gt;
Currently, various kinds of languages codes could be invoked from within ruby. The extension for C/C++ and Java are focused here.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== '''Ruby C/C++ extensions&amp;lt;ref&amp;gt;http://java.ociweb.com/mark/NFJS/RubyCExtensions.pdf&amp;lt;/ref&amp;gt;''' ==&lt;br /&gt;
By extending Ruby with C. The C libraries could be used directly in Ruby applications.&lt;br /&gt;
Ruby could call C codes in three ways: interpreter API, RubyInline, SWIG.&lt;br /&gt;
=== interpreter API ===&lt;br /&gt;
Ruby interpreter is implemented in C, its API can be used and no special API added for interacting with C like Java’s JNI is needed.&lt;br /&gt;
&lt;br /&gt;
The files needed include:&lt;br /&gt;
*'''extconf.rb'''&lt;br /&gt;
Used to generate Makefile&lt;br /&gt;
&lt;br /&gt;
Platform-specific Makefiles for compiling C extensions to Ruby is needed to be generated firstly.&lt;br /&gt;
&lt;br /&gt;
A simple sample is like below:&lt;br /&gt;
&lt;br /&gt;
create a file containing the following,&lt;br /&gt;
named extconf.rb by convention&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'mkmf'&lt;br /&gt;
extension_name = 'name'&lt;br /&gt;
dir_config(extension_name)&lt;br /&gt;
create_makefile(extension_name)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
And use by running&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ruby extconf.rb&lt;br /&gt;
make&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then generates&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
.so under UNIX/Linux&lt;br /&gt;
.so under Windows when building with Cygwin&lt;br /&gt;
.bundle under Mac OS X&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''C File'''&lt;br /&gt;
C codes to be invoked from Ruby&lt;br /&gt;
&lt;br /&gt;
An example Hello.c is shown below&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#include &amp;lt;ruby.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
// These C functions will be associated with&lt;br /&gt;
// methods of a Ruby class on the next page.&lt;br /&gt;
static VALUE hello(VALUE self, VALUE arg) {&lt;br /&gt;
 char* name = RSTRING(arg)-&amp;gt;ptr;&lt;br /&gt;
 printf(&amp;quot;Hello %s!\n&amp;quot;, name);&lt;br /&gt;
 return Qnil;&lt;br /&gt;
}&lt;br /&gt;
static VALUE goodbye(VALUE class) {&lt;br /&gt;
 printf(&amp;quot;Later dude!\n&amp;quot;);&lt;br /&gt;
 return Qnil;&lt;br /&gt;
}&lt;br /&gt;
// This is called when the Ruby interpreter loads this C extension.&lt;br /&gt;
// The part after &amp;quot;Init_&amp;quot; is the name of the C extension specified&lt;br /&gt;
// in extconf.rb, not the name of the C source file.&lt;br /&gt;
void Init_hello() {&lt;br /&gt;
 // Create a Ruby module.&lt;br /&gt;
 VALUE myModule = rb_define_module(&amp;quot;MyModule&amp;quot;);&lt;br /&gt;
 // Create a Ruby class in this module.&lt;br /&gt;
 // rb_cObject is defined in ruby.h&lt;br /&gt;
 VALUE myClass =&lt;br /&gt;
 rb_define_class_under(myModule, &amp;quot;MyClass&amp;quot;, rb_cObject);&lt;br /&gt;
 // Add an instance method to the Ruby class.&lt;br /&gt;
 int arg_count = 1;&lt;br /&gt;
 rb_define_method(myClass, &amp;quot;hello&amp;quot;, hello, arg_count);&lt;br /&gt;
 // Add a class method to the Ruby class.&lt;br /&gt;
 arg_count = 0;&lt;br /&gt;
 rb_define_module_function(myClass, &amp;quot;goodbye&amp;quot;, goodbye, arg_count);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*'''Ruby File'''&lt;br /&gt;
Ruby code that invokes C code&lt;br /&gt;
&lt;br /&gt;
An example client.rb is shown as below&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'hello'&lt;br /&gt;
include MyModule # so MyClass doesn't need MyModule:: prefix&lt;br /&gt;
obj = MyClass.new # MyClass is defined in C&lt;br /&gt;
obj.hello('Mark') # calling an object method&lt;br /&gt;
MyClass.goodbye # calling a class method&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally we could build and run&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ruby extconf.rb&lt;br /&gt;
make&lt;br /&gt;
ruby client.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then the output will display as&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Hello Mark!&lt;br /&gt;
Later dude!&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== RubyInline ===&lt;br /&gt;
[http://www.zenspider.com/ZSS/Products/RubyInline/ RubyInline] allows C code to be imbedded in Ruby code. It automatically determines if the code in question has changed and builds it only when necessary. The extensions are then automatically loaded into the class/module that defines it.&lt;br /&gt;
&lt;br /&gt;
To setup RubyInline, just use&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem install rubyinline&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SWIG ===&lt;br /&gt;
[http://en.wikipedia.org/wiki/SWIG SWIG] is a software development tool that connects programs written in C and C++ with a variety of high-level programming languages. SWIG is used with different types of target languages including common scripting languages such as Perl, PHP, Python, Tcl and Ruby. &lt;br /&gt;
&lt;br /&gt;
As an example, building Ruby Extensions under Windows 95/NT is shown as below&lt;br /&gt;
Building a SWIG extension to Ruby under Windows 95/NT is roughly similar to the process used with Unix. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
C:\swigtest&amp;gt; ruby extconf.rb&lt;br /&gt;
C:\swigtest&amp;gt; nmake&lt;br /&gt;
C:\swigtest&amp;gt; nmake install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== '''Ruby JAVA extensions''' ==&lt;br /&gt;
To extend Ruby with JAVA, the [http://jruby.org/ JRuby] is a good tool to use. JRuby is a high performance, stable, fully threaded Java implementation of the Ruby programming language. It is a Ruby interpreter written entirely in Java and can use Java capabilities from Ruby as well as can use Ruby capabilities from Java.&lt;br /&gt;
=== Using JRuby From Command-Line ===&lt;br /&gt;
*'''Steps to install'''&lt;br /&gt;
– download a binary release [http://jruby.org/ here]&lt;br /&gt;
&lt;br /&gt;
– unzip/untar the downloaded archive&lt;br /&gt;
&lt;br /&gt;
– set JRUBY_HOME environment variable to point to resulting directory&lt;br /&gt;
&lt;br /&gt;
– add $JRUBY_HOME/bin to PATH&lt;br /&gt;
*'''Steps to use'''&lt;br /&gt;
– jruby {script-name}&lt;br /&gt;
*'''Example'''&lt;br /&gt;
– hello.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
name = ARGV[0] || &amp;quot;you&amp;quot;&lt;br /&gt;
puts &amp;quot;Hello #{name}!&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
– run with&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
jruby hello.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
outputs&lt;br /&gt;
&amp;lt;pre&amp;gt; &lt;br /&gt;
Hello you!&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
– run with&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
jruby hello.rb Mark&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
outputs &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Hello Mark&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Using JAVA Classes in JRuby ===&lt;br /&gt;
To use java classes in JRuby, the program must require 'java'&lt;br /&gt;
&lt;br /&gt;
There several options to provide full names of Java classes to be used in JRuby&lt;br /&gt;
*'''option #1''' &lt;br /&gt;
provide full name when using&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
frame = javax.swing.JFrame.new('My Title')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*'''option #2''' &lt;br /&gt;
assign full class name to a constant &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
JFrame = javax.swing.JFrame&lt;br /&gt;
frame = JFrame.new('My Title')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*'''option #3'''&lt;br /&gt;
use include_class&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
include_class 'javax.swing.JFrame'&lt;br /&gt;
frame = JFrame.new('My Title')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*'''option #4'''&lt;br /&gt;
use include_class with an alias&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
include_class('java.lang.String') do |pkg_name, class_name|&lt;br /&gt;
 &amp;quot;J#{class_name}&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
msg = JString.new('My Message')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*'''option #5'''&lt;br /&gt;
use include_package&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module Swing&lt;br /&gt;
 include_package 'javax.swing'&lt;br /&gt;
end&lt;br /&gt;
frame = Swing::JFrame.new('My Title')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Qjia2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1h_jg&amp;diff=82944</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1h jg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1h_jg&amp;diff=82944"/>
		<updated>2014-02-04T22:42:20Z</updated>

		<summary type="html">&lt;p&gt;Qjia2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== '''Ruby libraries to load objects of other languages at run time''' ==&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby] is a dynamic, reflective, object-oriented, general-purpose programming language. It is easy to extend Ruby with new features by writing code in Ruby. But every now and then extending ruby with low-level languages, such as[http://en.wikipedia.org/wiki/C_(programming_language) C]/[http://en.wikipedia.org/wiki/C%2B%2B C++]/[http://en.wikipedia.org/wiki/Java_(programming_language) Java] is also necessary.&lt;br /&gt;
&lt;br /&gt;
Currently, various kinds of languages codes could be invoked from within ruby. The extension for C/C++ and Java are focused here.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== '''Ruby C/C++ extensions&amp;lt;ref&amp;gt;http://java.ociweb.com/mark/NFJS/RubyCExtensions.pdf&amp;lt;/ref&amp;gt;''' ==&lt;br /&gt;
By extending Ruby with C. The C libraries could be used directly in Ruby applications.&lt;br /&gt;
Ruby could call C codes in three ways: interpreter API, RubyInline, SWIG.&lt;br /&gt;
=== interpreter API ===&lt;br /&gt;
Ruby interpreter is implemented in C, its API can be used and no special API added for interacting with C like Java’s JNI is needed.&lt;br /&gt;
&lt;br /&gt;
The files needed include:&lt;br /&gt;
*'''extconf.rb'''&lt;br /&gt;
Used to generate Makefile&lt;br /&gt;
&lt;br /&gt;
Platform-specific Makefiles for compiling C extensions to Ruby is needed to be generated firstly.&lt;br /&gt;
&lt;br /&gt;
A simple sample is like below:&lt;br /&gt;
&lt;br /&gt;
create a file containing the following,&lt;br /&gt;
named extconf.rb by convention&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'mkmf'&lt;br /&gt;
extension_name = 'name'&lt;br /&gt;
dir_config(extension_name)&lt;br /&gt;
create_makefile(extension_name)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
And use by running&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ruby extconf.rb&lt;br /&gt;
make&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then generates&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
.so under UNIX/Linux&lt;br /&gt;
.so under Windows when building with Cygwin&lt;br /&gt;
.bundle under Mac OS X&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''C File'''&lt;br /&gt;
C codes to be invoked from Ruby&lt;br /&gt;
&lt;br /&gt;
An example Hello.c is shown below&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#include &amp;lt;ruby.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
// These C functions will be associated with&lt;br /&gt;
// methods of a Ruby class on the next page.&lt;br /&gt;
static VALUE hello(VALUE self, VALUE arg) {&lt;br /&gt;
 char* name = RSTRING(arg)-&amp;gt;ptr;&lt;br /&gt;
 printf(&amp;quot;Hello %s!\n&amp;quot;, name);&lt;br /&gt;
 return Qnil;&lt;br /&gt;
}&lt;br /&gt;
static VALUE goodbye(VALUE class) {&lt;br /&gt;
 printf(&amp;quot;Later dude!\n&amp;quot;);&lt;br /&gt;
 return Qnil;&lt;br /&gt;
}&lt;br /&gt;
// This is called when the Ruby interpreter loads this C extension.&lt;br /&gt;
// The part after &amp;quot;Init_&amp;quot; is the name of the C extension specified&lt;br /&gt;
// in extconf.rb, not the name of the C source file.&lt;br /&gt;
void Init_hello() {&lt;br /&gt;
 // Create a Ruby module.&lt;br /&gt;
 VALUE myModule = rb_define_module(&amp;quot;MyModule&amp;quot;);&lt;br /&gt;
 // Create a Ruby class in this module.&lt;br /&gt;
 // rb_cObject is defined in ruby.h&lt;br /&gt;
 VALUE myClass =&lt;br /&gt;
 rb_define_class_under(myModule, &amp;quot;MyClass&amp;quot;, rb_cObject);&lt;br /&gt;
 // Add an instance method to the Ruby class.&lt;br /&gt;
 int arg_count = 1;&lt;br /&gt;
 rb_define_method(myClass, &amp;quot;hello&amp;quot;, hello, arg_count);&lt;br /&gt;
 // Add a class method to the Ruby class.&lt;br /&gt;
 arg_count = 0;&lt;br /&gt;
 rb_define_module_function(myClass, &amp;quot;goodbye&amp;quot;, goodbye, arg_count);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*'''Ruby File'''&lt;br /&gt;
Ruby code that invokes C code&lt;br /&gt;
&lt;br /&gt;
An example client.rb is shown as below&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'hello'&lt;br /&gt;
include MyModule # so MyClass doesn't need MyModule:: prefix&lt;br /&gt;
obj = MyClass.new # MyClass is defined in C&lt;br /&gt;
obj.hello('Mark') # calling an object method&lt;br /&gt;
MyClass.goodbye # calling a class method&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally we could build and run&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ruby extconf.rb&lt;br /&gt;
make&lt;br /&gt;
ruby client.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then the output will display as&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Hello Mark!&lt;br /&gt;
Later dude!&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== RubyInline ===&lt;br /&gt;
[http://www.zenspider.com/ZSS/Products/RubyInline/ RubyInline] allows C code to be imbedded in Ruby code. It automatically determines if the code in question has changed and builds it only when necessary. The extensions are then automatically loaded into the class/module that defines it.&lt;br /&gt;
&lt;br /&gt;
To setup RubyInline, just use&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem install rubyinline&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SWIG ===&lt;br /&gt;
[http://en.wikipedia.org/wiki/SWIG SWIG] is a software development tool that connects programs written in C and C++ with a variety of high-level programming languages. SWIG is used with different types of target languages including common scripting languages such as Perl, PHP, Python, Tcl and Ruby. &lt;br /&gt;
&lt;br /&gt;
As an example, building Ruby Extensions under Windows 95/NT is shown as below&lt;br /&gt;
Building a SWIG extension to Ruby under Windows 95/NT is roughly similar to the process used with Unix. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
C:\swigtest&amp;gt; ruby extconf.rb&lt;br /&gt;
C:\swigtest&amp;gt; nmake&lt;br /&gt;
C:\swigtest&amp;gt; nmake install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== '''Ruby JAVA extensions''' ==&lt;br /&gt;
To extend Ruby with JAVA, the [http://jruby.org/ JRuby] is a good tool to use. JRuby is a high performance, stable, fully threaded Java implementation of the Ruby programming language. It is a Ruby interpreter written entirely in Java and can use Java capabilities from Ruby as well as can use Ruby capabilities from Java.&lt;br /&gt;
=== Using JRuby From Command-Line ===&lt;br /&gt;
*'''Steps to install'''&lt;br /&gt;
– download a binary release [http://jruby.org/ here]&lt;br /&gt;
&lt;br /&gt;
– unzip/untar the downloaded archive&lt;br /&gt;
&lt;br /&gt;
– set JRUBY_HOME environment variable to point to resulting directory&lt;br /&gt;
&lt;br /&gt;
– add $JRUBY_HOME/bin to PATH&lt;br /&gt;
*'''Steps to use'''&lt;br /&gt;
– jruby {script-name}&lt;br /&gt;
*'''Example'''&lt;br /&gt;
– hello.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
name = ARGV[0] || &amp;quot;you&amp;quot;&lt;br /&gt;
puts &amp;quot;Hello #{name}!&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
– run with&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
jruby hello.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
outputs&lt;br /&gt;
&amp;lt;pre&amp;gt; &lt;br /&gt;
Hello you!&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
– run with&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
jruby hello.rb Mark&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
outputs &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Hello Mark&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Qjia2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1h_jg&amp;diff=82943</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1h jg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1h_jg&amp;diff=82943"/>
		<updated>2014-02-04T22:40:53Z</updated>

		<summary type="html">&lt;p&gt;Qjia2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== '''Ruby libraries to load objects of other languages at run time''' ==&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby] is a dynamic, reflective, object-oriented, general-purpose programming language. It is easy to extend Ruby with new features by writing code in Ruby. But every now and then extending ruby with low-level languages, such as[http://en.wikipedia.org/wiki/C_(programming_language) C]/[http://en.wikipedia.org/wiki/C%2B%2B C++]/[http://en.wikipedia.org/wiki/Java_(programming_language) Java] is also necessary.&lt;br /&gt;
&lt;br /&gt;
Currently, various kinds of languages codes could be invoked from within ruby. The extension for C/C++ and Java are focused here.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== '''Ruby C/C++ extensions&amp;lt;ref&amp;gt;http://java.ociweb.com/mark/NFJS/RubyCExtensions.pdf&amp;lt;/ref&amp;gt;''' ==&lt;br /&gt;
By extending Ruby with C. The C libraries could be used directly in Ruby applications.&lt;br /&gt;
Ruby could call C codes in three ways: interpreter API, RubyInline, SWIG.&lt;br /&gt;
=== interpreter API ===&lt;br /&gt;
Ruby interpreter is implemented in C, its API can be used and no special API added for interacting with C like Java’s JNI is needed.&lt;br /&gt;
&lt;br /&gt;
The files needed include:&lt;br /&gt;
*'''extconf.rb'''&lt;br /&gt;
Used to generate Makefile&lt;br /&gt;
&lt;br /&gt;
Platform-specific Makefiles for compiling C extensions to Ruby is needed to be generated firstly.&lt;br /&gt;
&lt;br /&gt;
A simple sample is like below:&lt;br /&gt;
&lt;br /&gt;
create a file containing the following,&lt;br /&gt;
named extconf.rb by convention&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'mkmf'&lt;br /&gt;
extension_name = 'name'&lt;br /&gt;
dir_config(extension_name)&lt;br /&gt;
create_makefile(extension_name)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
And use by running&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ruby extconf.rb&lt;br /&gt;
make&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then generates&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
.so under UNIX/Linux&lt;br /&gt;
.so under Windows when building with Cygwin&lt;br /&gt;
.bundle under Mac OS X&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''C File'''&lt;br /&gt;
C codes to be invoked from Ruby&lt;br /&gt;
&lt;br /&gt;
An example Hello.c is shown below&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#include &amp;lt;ruby.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
// These C functions will be associated with&lt;br /&gt;
// methods of a Ruby class on the next page.&lt;br /&gt;
static VALUE hello(VALUE self, VALUE arg) {&lt;br /&gt;
 char* name = RSTRING(arg)-&amp;gt;ptr;&lt;br /&gt;
 printf(&amp;quot;Hello %s!\n&amp;quot;, name);&lt;br /&gt;
 return Qnil;&lt;br /&gt;
}&lt;br /&gt;
static VALUE goodbye(VALUE class) {&lt;br /&gt;
 printf(&amp;quot;Later dude!\n&amp;quot;);&lt;br /&gt;
 return Qnil;&lt;br /&gt;
}&lt;br /&gt;
// This is called when the Ruby interpreter loads this C extension.&lt;br /&gt;
// The part after &amp;quot;Init_&amp;quot; is the name of the C extension specified&lt;br /&gt;
// in extconf.rb, not the name of the C source file.&lt;br /&gt;
void Init_hello() {&lt;br /&gt;
 // Create a Ruby module.&lt;br /&gt;
 VALUE myModule = rb_define_module(&amp;quot;MyModule&amp;quot;);&lt;br /&gt;
 // Create a Ruby class in this module.&lt;br /&gt;
 // rb_cObject is defined in ruby.h&lt;br /&gt;
 VALUE myClass =&lt;br /&gt;
 rb_define_class_under(myModule, &amp;quot;MyClass&amp;quot;, rb_cObject);&lt;br /&gt;
 // Add an instance method to the Ruby class.&lt;br /&gt;
 int arg_count = 1;&lt;br /&gt;
 rb_define_method(myClass, &amp;quot;hello&amp;quot;, hello, arg_count);&lt;br /&gt;
 // Add a class method to the Ruby class.&lt;br /&gt;
 arg_count = 0;&lt;br /&gt;
 rb_define_module_function(myClass, &amp;quot;goodbye&amp;quot;, goodbye, arg_count);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*'''Ruby File'''&lt;br /&gt;
Ruby code that invokes C code&lt;br /&gt;
&lt;br /&gt;
An example client.rb is shown as below&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'hello'&lt;br /&gt;
include MyModule # so MyClass doesn't need MyModule:: prefix&lt;br /&gt;
obj = MyClass.new # MyClass is defined in C&lt;br /&gt;
obj.hello('Mark') # calling an object method&lt;br /&gt;
MyClass.goodbye # calling a class method&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally we could build and run&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ruby extconf.rb&lt;br /&gt;
make&lt;br /&gt;
ruby client.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then the output will display as&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Hello Mark!&lt;br /&gt;
Later dude!&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== RubyInline ===&lt;br /&gt;
[http://www.zenspider.com/ZSS/Products/RubyInline/ RubyInline] allows C code to be imbedded in Ruby code. It automatically determines if the code in question has changed and builds it only when necessary. The extensions are then automatically loaded into the class/module that defines it.&lt;br /&gt;
&lt;br /&gt;
To setup RubyInline, just use&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem install rubyinline&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SWIG ===&lt;br /&gt;
[http://en.wikipedia.org/wiki/SWIG SWIG] is a software development tool that connects programs written in C and C++ with a variety of high-level programming languages. SWIG is used with different types of target languages including common scripting languages such as Perl, PHP, Python, Tcl and Ruby. &lt;br /&gt;
&lt;br /&gt;
As an example, building Ruby Extensions under Windows 95/NT is shown as below&lt;br /&gt;
Building a SWIG extension to Ruby under Windows 95/NT is roughly similar to the process used with Unix. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
C:\swigtest&amp;gt; ruby extconf.rb&lt;br /&gt;
C:\swigtest&amp;gt; nmake&lt;br /&gt;
C:\swigtest&amp;gt; nmake install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== '''Ruby JAVA extensions''' ==&lt;br /&gt;
To extend Ruby with JAVA, the [http://jruby.org/ JRuby] is a good tool to use. JRuby is a high performance, stable, fully threaded Java implementation of the Ruby programming language. It is a Ruby interpreter written entirely in Java and can use Java capabilities from Ruby as well as can use Ruby capabilities from Java.&lt;br /&gt;
=== Using JRuby From Command-Line ===&lt;br /&gt;
*'''Steps to install'''&lt;br /&gt;
– download a binary release [www.jruby.org here]&lt;br /&gt;
&lt;br /&gt;
– unzip/untar the downloaded archive&lt;br /&gt;
&lt;br /&gt;
– set JRUBY_HOME environment variable to point to resulting directory&lt;br /&gt;
&lt;br /&gt;
– add $JRUBY_HOME/bin to PATH&lt;br /&gt;
*'''Steps to use'''&lt;br /&gt;
– jruby {script-name}&lt;br /&gt;
*'''Example'''&lt;br /&gt;
– hello.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
name = ARGV[0] || &amp;quot;you&amp;quot;&lt;br /&gt;
puts &amp;quot;Hello #{name}!&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
– run with&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
jruby hello.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
outputs&lt;br /&gt;
&amp;lt;pre&amp;gt; &lt;br /&gt;
Hello you!&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
– run with&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
jruby hello.rb Mark&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
outputs &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Hello Mark&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Qjia2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1h_jg&amp;diff=82942</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1h jg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1h_jg&amp;diff=82942"/>
		<updated>2014-02-04T22:40:06Z</updated>

		<summary type="html">&lt;p&gt;Qjia2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== '''Ruby libraries to load objects of other languages at run time''' ==&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby] is a dynamic, reflective, object-oriented, general-purpose programming language. It is easy to extend Ruby with new features by writing code in Ruby. But every now and then extending ruby with low-level languages, such as[http://en.wikipedia.org/wiki/C_(programming_language) C]/[http://en.wikipedia.org/wiki/C%2B%2B C++]/[http://en.wikipedia.org/wiki/Java_(programming_language) Java] is also necessary.&lt;br /&gt;
&lt;br /&gt;
Currently, various kinds of languages codes could be invoked from within ruby. The extension for C/C++ and Java are focused here.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== '''Ruby C/C++ extensions&amp;lt;ref&amp;gt;http://java.ociweb.com/mark/NFJS/RubyCExtensions.pdf&amp;lt;/ref&amp;gt;''' ==&lt;br /&gt;
By extending Ruby with C. The C libraries could be used directly in Ruby applications.&lt;br /&gt;
Ruby could call C codes in three ways: interpreter API, RubyInline, SWIG.&lt;br /&gt;
=== interpreter API ===&lt;br /&gt;
Ruby interpreter is implemented in C, its API can be used and no special API added for interacting with C like Java’s JNI is needed.&lt;br /&gt;
&lt;br /&gt;
The files needed include:&lt;br /&gt;
*'''extconf.rb'''&lt;br /&gt;
Used to generate Makefile&lt;br /&gt;
&lt;br /&gt;
Platform-specific Makefiles for compiling C extensions to Ruby is needed to be generated firstly.&lt;br /&gt;
&lt;br /&gt;
A simple sample is like below:&lt;br /&gt;
&lt;br /&gt;
create a file containing the following,&lt;br /&gt;
named extconf.rb by convention&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'mkmf'&lt;br /&gt;
extension_name = 'name'&lt;br /&gt;
dir_config(extension_name)&lt;br /&gt;
create_makefile(extension_name)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
And use by running&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ruby extconf.rb&lt;br /&gt;
make&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then generates&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
.so under UNIX/Linux&lt;br /&gt;
.so under Windows when building with Cygwin&lt;br /&gt;
.bundle under Mac OS X&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''C File'''&lt;br /&gt;
C codes to be invoked from Ruby&lt;br /&gt;
&lt;br /&gt;
An example Hello.c is shown below&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#include &amp;lt;ruby.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
// These C functions will be associated with&lt;br /&gt;
// methods of a Ruby class on the next page.&lt;br /&gt;
static VALUE hello(VALUE self, VALUE arg) {&lt;br /&gt;
 char* name = RSTRING(arg)-&amp;gt;ptr;&lt;br /&gt;
 printf(&amp;quot;Hello %s!\n&amp;quot;, name);&lt;br /&gt;
 return Qnil;&lt;br /&gt;
}&lt;br /&gt;
static VALUE goodbye(VALUE class) {&lt;br /&gt;
 printf(&amp;quot;Later dude!\n&amp;quot;);&lt;br /&gt;
 return Qnil;&lt;br /&gt;
}&lt;br /&gt;
// This is called when the Ruby interpreter loads this C extension.&lt;br /&gt;
// The part after &amp;quot;Init_&amp;quot; is the name of the C extension specified&lt;br /&gt;
// in extconf.rb, not the name of the C source file.&lt;br /&gt;
void Init_hello() {&lt;br /&gt;
 // Create a Ruby module.&lt;br /&gt;
 VALUE myModule = rb_define_module(&amp;quot;MyModule&amp;quot;);&lt;br /&gt;
 // Create a Ruby class in this module.&lt;br /&gt;
 // rb_cObject is defined in ruby.h&lt;br /&gt;
 VALUE myClass =&lt;br /&gt;
 rb_define_class_under(myModule, &amp;quot;MyClass&amp;quot;, rb_cObject);&lt;br /&gt;
 // Add an instance method to the Ruby class.&lt;br /&gt;
 int arg_count = 1;&lt;br /&gt;
 rb_define_method(myClass, &amp;quot;hello&amp;quot;, hello, arg_count);&lt;br /&gt;
 // Add a class method to the Ruby class.&lt;br /&gt;
 arg_count = 0;&lt;br /&gt;
 rb_define_module_function(myClass, &amp;quot;goodbye&amp;quot;, goodbye, arg_count);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*'''Ruby File'''&lt;br /&gt;
Ruby code that invokes C code&lt;br /&gt;
&lt;br /&gt;
An example client.rb is shown as below&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'hello'&lt;br /&gt;
include MyModule # so MyClass doesn't need MyModule:: prefix&lt;br /&gt;
obj = MyClass.new # MyClass is defined in C&lt;br /&gt;
obj.hello('Mark') # calling an object method&lt;br /&gt;
MyClass.goodbye # calling a class method&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally we could build and run&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ruby extconf.rb&lt;br /&gt;
make&lt;br /&gt;
ruby client.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then the output will display as&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Hello Mark!&lt;br /&gt;
Later dude!&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== RubyInline ===&lt;br /&gt;
[http://www.zenspider.com/ZSS/Products/RubyInline/ RubyInline] allows C code to be imbedded in Ruby code. It automatically determines if the code in question has changed and builds it only when necessary. The extensions are then automatically loaded into the class/module that defines it.&lt;br /&gt;
&lt;br /&gt;
To setup RubyInline, just use&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem install rubyinline&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SWIG ===&lt;br /&gt;
[http://en.wikipedia.org/wiki/SWIG SWIG] is a software development tool that connects programs written in C and C++ with a variety of high-level programming languages. SWIG is used with different types of target languages including common scripting languages such as Perl, PHP, Python, Tcl and Ruby. &lt;br /&gt;
&lt;br /&gt;
As an example, building Ruby Extensions under Windows 95/NT is shown as below&lt;br /&gt;
Building a SWIG extension to Ruby under Windows 95/NT is roughly similar to the process used with Unix. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
C:\swigtest&amp;gt; ruby extconf.rb&lt;br /&gt;
C:\swigtest&amp;gt; nmake&lt;br /&gt;
C:\swigtest&amp;gt; nmake install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== '''Ruby JAVA extensions''' ==&lt;br /&gt;
To extend Ruby with JAVA, the [http://jruby.org/ JRuby] is a good tool to use. JRuby is a high performance, stable, fully threaded Java implementation of the Ruby programming language. It is a Ruby interpreter written entirely in Java and can use Java capabilities from Ruby as well as can use Ruby capabilities from Java.&lt;br /&gt;
=== Using JRuby From Command-Line ===&lt;br /&gt;
*'''Steps to install'''&lt;br /&gt;
– download a binary release [www.jruby.org here]&lt;br /&gt;
– unzip/untar the downloaded archive&lt;br /&gt;
– set JRUBY_HOME environment variable to point to resulting directory&lt;br /&gt;
– add $JRUBY_HOME/bin to PATH&lt;br /&gt;
*'''Steps to use'''&lt;br /&gt;
– jruby {script-name}&lt;br /&gt;
*'''Example'''&lt;br /&gt;
– hello.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
name = ARGV[0] || &amp;quot;you&amp;quot;&lt;br /&gt;
puts &amp;quot;Hello #{name}!&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
– run with&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
jruby hello.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
outputs&lt;br /&gt;
&amp;lt;pre&amp;gt; &lt;br /&gt;
Hello you!&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
– run with&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
jruby hello.rb Mark&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
outputs &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Hello Mark&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Qjia2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1h_jg&amp;diff=82941</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1h jg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1h_jg&amp;diff=82941"/>
		<updated>2014-02-04T22:28:38Z</updated>

		<summary type="html">&lt;p&gt;Qjia2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== '''Ruby libraries to load objects of other languages at run time''' ==&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby] is a dynamic, reflective, object-oriented, general-purpose programming language. It is easy to extend Ruby with new features by writing code in Ruby. But every now and then extending ruby with low-level languages, such as[http://en.wikipedia.org/wiki/C_(programming_language) C]/[http://en.wikipedia.org/wiki/C%2B%2B C++]/[http://en.wikipedia.org/wiki/Java_(programming_language) Java] is also necessary.&lt;br /&gt;
&lt;br /&gt;
Currently, various kinds of languages codes could be invoked from within ruby. The extension for C/C++ and Java are focused here.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== '''Ruby C/C++ extensions&amp;lt;ref&amp;gt;http://java.ociweb.com/mark/NFJS/RubyCExtensions.pdf&amp;lt;/ref&amp;gt;''' ==&lt;br /&gt;
By extending Ruby with C. The C libraries could be used directly in Ruby applications.&lt;br /&gt;
Ruby could call C codes in three ways: interpreter API, RubyInline, SWIG.&lt;br /&gt;
=== interpreter API ===&lt;br /&gt;
Ruby interpreter is implemented in C, its API can be used and no special API added for interacting with C like Java’s JNI is needed.&lt;br /&gt;
&lt;br /&gt;
The files needed include:&lt;br /&gt;
*'''extconf.rb'''&lt;br /&gt;
Used to generate Makefile&lt;br /&gt;
&lt;br /&gt;
Platform-specific Makefiles for compiling C extensions to Ruby is needed to be generated firstly.&lt;br /&gt;
&lt;br /&gt;
A simple sample is like below:&lt;br /&gt;
&lt;br /&gt;
create a file containing the following,&lt;br /&gt;
named extconf.rb by convention&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'mkmf'&lt;br /&gt;
extension_name = 'name'&lt;br /&gt;
dir_config(extension_name)&lt;br /&gt;
create_makefile(extension_name)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
And use by running&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ruby extconf.rb&lt;br /&gt;
make&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then generates&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
.so under UNIX/Linux&lt;br /&gt;
.so under Windows when building with Cygwin&lt;br /&gt;
.bundle under Mac OS X&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''C File'''&lt;br /&gt;
C codes to be invoked from Ruby&lt;br /&gt;
&lt;br /&gt;
An example Hello.c is shown below&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#include &amp;lt;ruby.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
// These C functions will be associated with&lt;br /&gt;
// methods of a Ruby class on the next page.&lt;br /&gt;
static VALUE hello(VALUE self, VALUE arg) {&lt;br /&gt;
 char* name = RSTRING(arg)-&amp;gt;ptr;&lt;br /&gt;
 printf(&amp;quot;Hello %s!\n&amp;quot;, name);&lt;br /&gt;
 return Qnil;&lt;br /&gt;
}&lt;br /&gt;
static VALUE goodbye(VALUE class) {&lt;br /&gt;
 printf(&amp;quot;Later dude!\n&amp;quot;);&lt;br /&gt;
 return Qnil;&lt;br /&gt;
}&lt;br /&gt;
// This is called when the Ruby interpreter loads this C extension.&lt;br /&gt;
// The part after &amp;quot;Init_&amp;quot; is the name of the C extension specified&lt;br /&gt;
// in extconf.rb, not the name of the C source file.&lt;br /&gt;
void Init_hello() {&lt;br /&gt;
 // Create a Ruby module.&lt;br /&gt;
 VALUE myModule = rb_define_module(&amp;quot;MyModule&amp;quot;);&lt;br /&gt;
 // Create a Ruby class in this module.&lt;br /&gt;
 // rb_cObject is defined in ruby.h&lt;br /&gt;
 VALUE myClass =&lt;br /&gt;
 rb_define_class_under(myModule, &amp;quot;MyClass&amp;quot;, rb_cObject);&lt;br /&gt;
 // Add an instance method to the Ruby class.&lt;br /&gt;
 int arg_count = 1;&lt;br /&gt;
 rb_define_method(myClass, &amp;quot;hello&amp;quot;, hello, arg_count);&lt;br /&gt;
 // Add a class method to the Ruby class.&lt;br /&gt;
 arg_count = 0;&lt;br /&gt;
 rb_define_module_function(myClass, &amp;quot;goodbye&amp;quot;, goodbye, arg_count);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*'''Ruby File'''&lt;br /&gt;
Ruby code that invokes C code&lt;br /&gt;
&lt;br /&gt;
An example client.rb is shown as below&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'hello'&lt;br /&gt;
include MyModule # so MyClass doesn't need MyModule:: prefix&lt;br /&gt;
obj = MyClass.new # MyClass is defined in C&lt;br /&gt;
obj.hello('Mark') # calling an object method&lt;br /&gt;
MyClass.goodbye # calling a class method&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally we could build and run&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ruby extconf.rb&lt;br /&gt;
make&lt;br /&gt;
ruby client.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then the output will display as&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Hello Mark!&lt;br /&gt;
Later dude!&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== RubyInline ===&lt;br /&gt;
[http://www.zenspider.com/ZSS/Products/RubyInline/ RubyInline] allows C code to be imbedded in Ruby code. It automatically determines if the code in question has changed and builds it only when necessary. The extensions are then automatically loaded into the class/module that defines it.&lt;br /&gt;
&lt;br /&gt;
To setup RubyInline, just use&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem install rubyinline&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SWIG ===&lt;br /&gt;
[http://en.wikipedia.org/wiki/SWIG SWIG] is a software development tool that connects programs written in C and C++ with a variety of high-level programming languages. SWIG is used with different types of target languages including common scripting languages such as Perl, PHP, Python, Tcl and Ruby. &lt;br /&gt;
&lt;br /&gt;
As an example, building Ruby Extensions under Windows 95/NT is shown as below&lt;br /&gt;
Building a SWIG extension to Ruby under Windows 95/NT is roughly similar to the process used with Unix. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
C:\swigtest&amp;gt; ruby extconf.rb&lt;br /&gt;
C:\swigtest&amp;gt; nmake&lt;br /&gt;
C:\swigtest&amp;gt; nmake install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Ruby JAVA extensions''' ==&lt;/div&gt;</summary>
		<author><name>Qjia2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1h_jg&amp;diff=82940</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1h jg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1h_jg&amp;diff=82940"/>
		<updated>2014-02-04T22:22:16Z</updated>

		<summary type="html">&lt;p&gt;Qjia2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== '''Ruby libraries to load objects of other languages at run time''' ==&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby] is a dynamic, reflective, object-oriented, general-purpose programming language. It is easy to extend Ruby with new features by writing code in Ruby. But every now and then extending ruby with low-level languages, such as[http://en.wikipedia.org/wiki/C_(programming_language) C]/[http://en.wikipedia.org/wiki/C%2B%2B C++]/[http://en.wikipedia.org/wiki/Java_(programming_language) Java] is also necessary.&lt;br /&gt;
&lt;br /&gt;
Currently, various kinds of languages codes could be invoked from within ruby. The extension for C/C++ and Java are focused here.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== '''Ruby C/C++ extensions&amp;lt;ref&amp;gt;http://java.ociweb.com/mark/NFJS/RubyCExtensions.pdf&amp;lt;/ref&amp;gt;''' ==&lt;br /&gt;
By extending Ruby with C. The C libraries could be used directly in Ruby applications.&lt;br /&gt;
Ruby could call C codes in three ways: interpreter API, RubyInline, SWIG.&lt;br /&gt;
=== interpreter API ===&lt;br /&gt;
Ruby interpreter is implemented in C, its API can be used and no special API added for interacting with C like Java’s JNI is needed.&lt;br /&gt;
&lt;br /&gt;
The files needed include:&lt;br /&gt;
*'''extconf.rb'''&lt;br /&gt;
Used to generate Makefile&lt;br /&gt;
&lt;br /&gt;
Platform-specific Makefiles for compiling C extensions to Ruby is needed to be generated firstly.&lt;br /&gt;
&lt;br /&gt;
A simple sample is like below:&lt;br /&gt;
&lt;br /&gt;
create a file containing the following,&lt;br /&gt;
named extconf.rb by convention&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'mkmf'&lt;br /&gt;
extension_name = 'name'&lt;br /&gt;
dir_config(extension_name)&lt;br /&gt;
create_makefile(extension_name)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
And use by running&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ruby extconf.rb&lt;br /&gt;
make&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then generates&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
.so under UNIX/Linux&lt;br /&gt;
.so under Windows when building with Cygwin&lt;br /&gt;
.bundle under Mac OS X&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''C File'''&lt;br /&gt;
C codes to be invoked from Ruby&lt;br /&gt;
&lt;br /&gt;
An example Hello.c is shown below&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#include &amp;lt;ruby.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
// These C functions will be associated with&lt;br /&gt;
// methods of a Ruby class on the next page.&lt;br /&gt;
static VALUE hello(VALUE self, VALUE arg) {&lt;br /&gt;
 char* name = RSTRING(arg)-&amp;gt;ptr;&lt;br /&gt;
 printf(&amp;quot;Hello %s!\n&amp;quot;, name);&lt;br /&gt;
 return Qnil;&lt;br /&gt;
}&lt;br /&gt;
static VALUE goodbye(VALUE class) {&lt;br /&gt;
 printf(&amp;quot;Later dude!\n&amp;quot;);&lt;br /&gt;
 return Qnil;&lt;br /&gt;
}&lt;br /&gt;
// This is called when the Ruby interpreter loads this C extension.&lt;br /&gt;
// The part after &amp;quot;Init_&amp;quot; is the name of the C extension specified&lt;br /&gt;
// in extconf.rb, not the name of the C source file.&lt;br /&gt;
void Init_hello() {&lt;br /&gt;
 // Create a Ruby module.&lt;br /&gt;
 VALUE myModule = rb_define_module(&amp;quot;MyModule&amp;quot;);&lt;br /&gt;
 // Create a Ruby class in this module.&lt;br /&gt;
 // rb_cObject is defined in ruby.h&lt;br /&gt;
 VALUE myClass =&lt;br /&gt;
 rb_define_class_under(myModule, &amp;quot;MyClass&amp;quot;, rb_cObject);&lt;br /&gt;
 // Add an instance method to the Ruby class.&lt;br /&gt;
 int arg_count = 1;&lt;br /&gt;
 rb_define_method(myClass, &amp;quot;hello&amp;quot;, hello, arg_count);&lt;br /&gt;
 // Add a class method to the Ruby class.&lt;br /&gt;
 arg_count = 0;&lt;br /&gt;
 rb_define_module_function(myClass, &amp;quot;goodbye&amp;quot;, goodbye, arg_count);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*'''Ruby File'''&lt;br /&gt;
Ruby code that invokes C code&lt;br /&gt;
&lt;br /&gt;
An example client.rb is shown as below&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'hello'&lt;br /&gt;
include MyModule # so MyClass doesn't need MyModule:: prefix&lt;br /&gt;
obj = MyClass.new # MyClass is defined in C&lt;br /&gt;
obj.hello('Mark') # calling an object method&lt;br /&gt;
MyClass.goodbye # calling a class method&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally we could build and run&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ruby extconf.rb&lt;br /&gt;
make&lt;br /&gt;
ruby client.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then the output will display as&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Hello Mark!&lt;br /&gt;
Later dude!&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== RubyInline ===&lt;br /&gt;
[http://www.zenspider.com/ZSS/Products/RubyInline/ RubyInline] allows C code to be imbedded in Ruby code. It automatically determines if the code in question has changed and builds it only when necessary. The extensions are then automatically loaded into the class/module that defines it.&lt;br /&gt;
&lt;br /&gt;
To setup RubyInline, just use&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem install rubyinline&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SWIG ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Ruby JAVA extensions''' ==&lt;/div&gt;</summary>
		<author><name>Qjia2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1h_jg&amp;diff=82939</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1h jg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1h_jg&amp;diff=82939"/>
		<updated>2014-02-04T22:21:30Z</updated>

		<summary type="html">&lt;p&gt;Qjia2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== '''Ruby libraries to load objects of other languages at run time''' ==&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby] is a dynamic, reflective, object-oriented, general-purpose programming language. It is easy to extend Ruby with new features by writing code in Ruby. But every now and then extending ruby with low-level languages, such as[http://en.wikipedia.org/wiki/C_(programming_language) C]/[http://en.wikipedia.org/wiki/C%2B%2B C++]/[http://en.wikipedia.org/wiki/Java_(programming_language) Java] is also necessary.&lt;br /&gt;
&lt;br /&gt;
Currently, various kinds of languages codes could be invoked from within ruby. The extension for C/C++ and Java are focused here.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== '''Ruby C/C++ extensions&amp;lt;ref&amp;gt;http://java.ociweb.com/mark/NFJS/RubyCExtensions.pdf&amp;lt;/ref&amp;gt;''' ==&lt;br /&gt;
By extending Ruby with C. The C libraries could be used directly in Ruby applications.&lt;br /&gt;
Ruby could call C codes in three ways: interpreter API, RubyInline, SWIG.&lt;br /&gt;
=== interpreter API ===&lt;br /&gt;
Ruby interpreter is implemented in C, its API can be used and no special API added for interacting with C like Java’s JNI is needed.&lt;br /&gt;
&lt;br /&gt;
The files needed include:&lt;br /&gt;
*'''extconf.rb'''&lt;br /&gt;
Used to generate Makefile&lt;br /&gt;
&lt;br /&gt;
Platform-specific Makefiles for compiling C extensions to Ruby is needed to be generated firstly.&lt;br /&gt;
&lt;br /&gt;
A simple sample is like below:&lt;br /&gt;
&lt;br /&gt;
create a file containing the following,&lt;br /&gt;
named extconf.rb by convention&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'mkmf'&lt;br /&gt;
extension_name = 'name'&lt;br /&gt;
dir_config(extension_name)&lt;br /&gt;
create_makefile(extension_name)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
And use by running&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ruby extconf.rb&lt;br /&gt;
make&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then generates&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
.so under UNIX/Linux&lt;br /&gt;
.so under Windows when building with Cygwin&lt;br /&gt;
.bundle under Mac OS X&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''C File'''&lt;br /&gt;
C codes to be invoked from Ruby&lt;br /&gt;
&lt;br /&gt;
An example Hello.c is shown below&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#include &amp;lt;ruby.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
// These C functions will be associated with&lt;br /&gt;
// methods of a Ruby class on the next page.&lt;br /&gt;
static VALUE hello(VALUE self, VALUE arg) {&lt;br /&gt;
 char* name = RSTRING(arg)-&amp;gt;ptr;&lt;br /&gt;
 printf(&amp;quot;Hello %s!\n&amp;quot;, name);&lt;br /&gt;
 return Qnil;&lt;br /&gt;
}&lt;br /&gt;
static VALUE goodbye(VALUE class) {&lt;br /&gt;
 printf(&amp;quot;Later dude!\n&amp;quot;);&lt;br /&gt;
 return Qnil;&lt;br /&gt;
}&lt;br /&gt;
// This is called when the Ruby interpreter loads this C extension.&lt;br /&gt;
// The part after &amp;quot;Init_&amp;quot; is the name of the C extension specified&lt;br /&gt;
// in extconf.rb, not the name of the C source file.&lt;br /&gt;
void Init_hello() {&lt;br /&gt;
 // Create a Ruby module.&lt;br /&gt;
 VALUE myModule = rb_define_module(&amp;quot;MyModule&amp;quot;);&lt;br /&gt;
 // Create a Ruby class in this module.&lt;br /&gt;
 // rb_cObject is defined in ruby.h&lt;br /&gt;
 VALUE myClass =&lt;br /&gt;
 rb_define_class_under(myModule, &amp;quot;MyClass&amp;quot;, rb_cObject);&lt;br /&gt;
 // Add an instance method to the Ruby class.&lt;br /&gt;
 int arg_count = 1;&lt;br /&gt;
 rb_define_method(myClass, &amp;quot;hello&amp;quot;, hello, arg_count);&lt;br /&gt;
 // Add a class method to the Ruby class.&lt;br /&gt;
 arg_count = 0;&lt;br /&gt;
 rb_define_module_function(myClass, &amp;quot;goodbye&amp;quot;, goodbye, arg_count);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*'''Ruby File'''&lt;br /&gt;
Ruby code that invokes C code&lt;br /&gt;
&lt;br /&gt;
An example client.rb is shown as below&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'hello'&lt;br /&gt;
include MyModule # so MyClass doesn't need MyModule:: prefix&lt;br /&gt;
obj = MyClass.new # MyClass is defined in C&lt;br /&gt;
obj.hello('Mark') # calling an object method&lt;br /&gt;
MyClass.goodbye # calling a class method&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally we could build and run&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ruby extconf.rb&lt;br /&gt;
make&lt;br /&gt;
ruby client.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then the output will display as&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Hello Mark!&lt;br /&gt;
Later dude!&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== RubyInline ===&lt;br /&gt;
[https://github.com/seattlerb/rubyinline RubyInline] allows C code to be imbedded in Ruby code. It automatically determines if the code in question has changed and builds it only when necessary. The extensions are then automatically loaded into the class/module that defines it.&lt;br /&gt;
&lt;br /&gt;
To setup RubyInline, just use&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem install rubyinline&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SWIG ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Ruby JAVA extensions''' ==&lt;/div&gt;</summary>
		<author><name>Qjia2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1h_jg&amp;diff=82938</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1h jg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1h_jg&amp;diff=82938"/>
		<updated>2014-02-04T21:57:30Z</updated>

		<summary type="html">&lt;p&gt;Qjia2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== '''Ruby libraries to load objects of other languages at run time''' ==&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby] is a dynamic, reflective, object-oriented, general-purpose programming language. It is easy to extend Ruby with new features by writing code in Ruby. But every now and then extending ruby with low-level languages, such as[http://en.wikipedia.org/wiki/C_(programming_language) C]/[http://en.wikipedia.org/wiki/C%2B%2B C++]/[http://en.wikipedia.org/wiki/Java_(programming_language) Java] is also necessary.&lt;br /&gt;
&lt;br /&gt;
Currently, various kinds of languages codes could be invoked from within ruby. The extension for C/C++ and Java are focused here.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== '''Ruby C/C++ extensions&amp;lt;ref&amp;gt;http://java.ociweb.com/mark/NFJS/RubyCExtensions.pdf&amp;lt;/ref&amp;gt;''' ==&lt;br /&gt;
By extending Ruby with C. The C libraries could be used directly in Ruby applications.&lt;br /&gt;
Ruby could call C codes in three ways: interpreter API, RubyInline, SWIG.&lt;br /&gt;
=== interpreter API ===&lt;br /&gt;
Ruby interpreter is implemented in C, its API can be used and no special API added for interacting with C like Java’s JNI is needed.&lt;br /&gt;
&lt;br /&gt;
The files needed include:&lt;br /&gt;
*'''extconf.rb'''&lt;br /&gt;
Used to generate Makefile&lt;br /&gt;
&lt;br /&gt;
Platform-specific Makefiles for compiling C extensions to Ruby is needed to be generated firstly.&lt;br /&gt;
&lt;br /&gt;
A simple sample is like below:&lt;br /&gt;
&lt;br /&gt;
create a file containing the following,&lt;br /&gt;
named extconf.rb by convention&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'mkmf'&lt;br /&gt;
extension_name = 'name'&lt;br /&gt;
dir_config(extension_name)&lt;br /&gt;
create_makefile(extension_name)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
And use by running&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ruby extconf.rb&lt;br /&gt;
make&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then generates&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
.so under UNIX/Linux&lt;br /&gt;
.so under Windows when building with Cygwin&lt;br /&gt;
.bundle under Mac OS X&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''C File'''&lt;br /&gt;
C codes to be invoked from Ruby&lt;br /&gt;
&lt;br /&gt;
An example Hello.c is shown below&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#include &amp;lt;ruby.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
// These C functions will be associated with&lt;br /&gt;
// methods of a Ruby class on the next page.&lt;br /&gt;
static VALUE hello(VALUE self, VALUE arg) {&lt;br /&gt;
 char* name = RSTRING(arg)-&amp;gt;ptr;&lt;br /&gt;
 printf(&amp;quot;Hello %s!\n&amp;quot;, name);&lt;br /&gt;
 return Qnil;&lt;br /&gt;
}&lt;br /&gt;
static VALUE goodbye(VALUE class) {&lt;br /&gt;
 printf(&amp;quot;Later dude!\n&amp;quot;);&lt;br /&gt;
 return Qnil;&lt;br /&gt;
}&lt;br /&gt;
// This is called when the Ruby interpreter loads this C extension.&lt;br /&gt;
// The part after &amp;quot;Init_&amp;quot; is the name of the C extension specified&lt;br /&gt;
// in extconf.rb, not the name of the C source file.&lt;br /&gt;
void Init_hello() {&lt;br /&gt;
 // Create a Ruby module.&lt;br /&gt;
 VALUE myModule = rb_define_module(&amp;quot;MyModule&amp;quot;);&lt;br /&gt;
 // Create a Ruby class in this module.&lt;br /&gt;
 // rb_cObject is defined in ruby.h&lt;br /&gt;
 VALUE myClass =&lt;br /&gt;
 rb_define_class_under(myModule, &amp;quot;MyClass&amp;quot;, rb_cObject);&lt;br /&gt;
 // Add an instance method to the Ruby class.&lt;br /&gt;
 int arg_count = 1;&lt;br /&gt;
 rb_define_method(myClass, &amp;quot;hello&amp;quot;, hello, arg_count);&lt;br /&gt;
 // Add a class method to the Ruby class.&lt;br /&gt;
 arg_count = 0;&lt;br /&gt;
 rb_define_module_function(myClass, &amp;quot;goodbye&amp;quot;, goodbye, arg_count);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*'''Ruby File'''&lt;br /&gt;
Ruby code that invokes C code&lt;br /&gt;
&lt;br /&gt;
An example client.rb is shown as below&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'hello'&lt;br /&gt;
include MyModule # so MyClass doesn't need MyModule:: prefix&lt;br /&gt;
obj = MyClass.new # MyClass is defined in C&lt;br /&gt;
obj.hello('Mark') # calling an object method&lt;br /&gt;
MyClass.goodbye # calling a class method&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally we could build and run&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ruby extconf.rb&lt;br /&gt;
make&lt;br /&gt;
ruby client.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then the output will display as&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Hello Mark!&lt;br /&gt;
Later dude!&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== RubyInline ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== SWIG ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Ruby JAVA extensions''' ==&lt;/div&gt;</summary>
		<author><name>Qjia2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1h_jg&amp;diff=82937</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1h jg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1h_jg&amp;diff=82937"/>
		<updated>2014-02-04T21:55:59Z</updated>

		<summary type="html">&lt;p&gt;Qjia2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== '''Ruby libraries to load objects of other languages at run time''' ==&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby] is a dynamic, reflective, object-oriented, general-purpose programming language. It is easy to extend Ruby with new features by writing code in Ruby. But every now and then extending ruby with low-level languages, such as[http://en.wikipedia.org/wiki/C_(programming_language) C]/[http://en.wikipedia.org/wiki/C%2B%2B C++]/[http://en.wikipedia.org/wiki/Java_(programming_language) Java] is also necessary.&lt;br /&gt;
&lt;br /&gt;
Currently, various kinds of languages codes could be invoked from within ruby. The extension for C/C++ and Java are focused here.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== '''Ruby C/C++ extensions&amp;lt;ref&amp;gt;http://java.ociweb.com/mark/NFJS/RubyCExtensions.pdf&amp;lt;/ref&amp;gt;''' ==&lt;br /&gt;
By extending Ruby with C. The C libraries could be used directly in Ruby applications.&lt;br /&gt;
Ruby could call C codes in three ways: interpreter API, RubyInline, SWIG.&lt;br /&gt;
=== interpreter API ===&lt;br /&gt;
Ruby interpreter is implemented in C, its API can be used and no special API added for interacting with C like Java’s JNI is needed.&lt;br /&gt;
&lt;br /&gt;
The files needed include:&lt;br /&gt;
*'''extconf.rb'''&lt;br /&gt;
Used to generate Makefile&lt;br /&gt;
&lt;br /&gt;
Platform-specific Makefiles for compiling C extensions to Ruby is needed to be generated firstly.&lt;br /&gt;
&lt;br /&gt;
A simple sample is like below:&lt;br /&gt;
&lt;br /&gt;
create a file containing the following,&lt;br /&gt;
named extconf.rb by convention&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'mkmf'&lt;br /&gt;
extension_name = 'name'&lt;br /&gt;
dir_config(extension_name)&lt;br /&gt;
create_makefile(extension_name)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
And use by running&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ruby extconf.rb&lt;br /&gt;
make&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then generates&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
.so under UNIX/Linux&lt;br /&gt;
.so under Windows when building with Cygwin&lt;br /&gt;
.bundle under Mac OS X&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''C File'''&lt;br /&gt;
C codes to be invoked from Ruby&lt;br /&gt;
&lt;br /&gt;
An example Hello.c is shown below&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#include &amp;lt;ruby.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
// These C functions will be associated with&lt;br /&gt;
// methods of a Ruby class on the next page.&lt;br /&gt;
static VALUE hello(VALUE self, VALUE arg) {&lt;br /&gt;
 char* name = RSTRING(arg)-&amp;gt;ptr;&lt;br /&gt;
 printf(&amp;quot;Hello %s!\n&amp;quot;, name);&lt;br /&gt;
 return Qnil;&lt;br /&gt;
}&lt;br /&gt;
static VALUE goodbye(VALUE class) {&lt;br /&gt;
 printf(&amp;quot;Later dude!\n&amp;quot;);&lt;br /&gt;
 return Qnil;&lt;br /&gt;
}&lt;br /&gt;
// This is called when the Ruby interpreter loads this C extension.&lt;br /&gt;
// The part after &amp;quot;Init_&amp;quot; is the name of the C extension specified&lt;br /&gt;
// in extconf.rb, not the name of the C source file.&lt;br /&gt;
void Init_hello() {&lt;br /&gt;
 // Create a Ruby module.&lt;br /&gt;
 VALUE myModule = rb_define_module(&amp;quot;MyModule&amp;quot;);&lt;br /&gt;
 // Create a Ruby class in this module.&lt;br /&gt;
 // rb_cObject is defined in ruby.h&lt;br /&gt;
 VALUE myClass =&lt;br /&gt;
 rb_define_class_under(myModule, &amp;quot;MyClass&amp;quot;, rb_cObject);&lt;br /&gt;
 // Add an instance method to the Ruby class.&lt;br /&gt;
 int arg_count = 1;&lt;br /&gt;
 rb_define_method(myClass, &amp;quot;hello&amp;quot;, hello, arg_count);&lt;br /&gt;
 // Add a class method to the Ruby class.&lt;br /&gt;
 arg_count = 0;&lt;br /&gt;
 rb_define_module_function(myClass, &amp;quot;goodbye&amp;quot;, goodbye, arg_count);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*'''Ruby File'''&lt;br /&gt;
Ruby code that invokes C code&lt;br /&gt;
&lt;br /&gt;
An example client.rb is shown as below&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'hello'&lt;br /&gt;
include MyModule # so MyClass doesn't need MyModule:: prefix&lt;br /&gt;
obj = MyClass.new # MyClass is defined in C&lt;br /&gt;
obj.hello('Mark') # calling an object method&lt;br /&gt;
MyClass.goodbye # calling a class method&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Finally we could build and run&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ruby extconf.rb&lt;br /&gt;
make&lt;br /&gt;
ruby client.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== RubyInline ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== SWIG ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Ruby JAVA extensions''' ==&lt;/div&gt;</summary>
		<author><name>Qjia2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1h_jg&amp;diff=82936</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1h jg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1h_jg&amp;diff=82936"/>
		<updated>2014-02-04T21:50:48Z</updated>

		<summary type="html">&lt;p&gt;Qjia2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== '''Ruby libraries to load objects of other languages at run time''' ==&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby] is a dynamic, reflective, object-oriented, general-purpose programming language. It is easy to extend Ruby with new features by writing code in Ruby. But every now and then extending ruby with low-level languages, such as[http://en.wikipedia.org/wiki/C_(programming_language) C]/[http://en.wikipedia.org/wiki/C%2B%2B C++]/[http://en.wikipedia.org/wiki/Java_(programming_language) Java] is also necessary.&lt;br /&gt;
&lt;br /&gt;
Currently, various kinds of languages codes could be invoked from within ruby. The extension for C/C++ and Java are focused here.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== '''Ruby C/C++ extensions&amp;lt;ref&amp;gt;http://java.ociweb.com/mark/NFJS/RubyCExtensions.pdf&amp;lt;/ref&amp;gt;''' ==&lt;br /&gt;
By extending Ruby with C. The C libraries could be used directly in Ruby applications.&lt;br /&gt;
Ruby could call C codes in three ways: interpreter API, RubyInline, SWIG.&lt;br /&gt;
=== interpreter API ===&lt;br /&gt;
Ruby interpreter is implemented in C, its API can be used and no special API added for interacting with C like Java’s JNI is needed.&lt;br /&gt;
The files needed include:&lt;br /&gt;
*'''extconf.rb'''&lt;br /&gt;
Used to generate Makefile&lt;br /&gt;
&lt;br /&gt;
Platform-specific Makefiles for compiling C extensions to Ruby is needed to be generated firstly.&lt;br /&gt;
&lt;br /&gt;
A simple sample is like below:&lt;br /&gt;
&lt;br /&gt;
create a file containing the following,&lt;br /&gt;
named extconf.rb by convention&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'mkmf'&lt;br /&gt;
extension_name = 'name'&lt;br /&gt;
dir_config(extension_name)&lt;br /&gt;
create_makefile(extension_name)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
And use by running&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ruby extconf.rb&lt;br /&gt;
make&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then generates&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
.so under UNIX/Linux&lt;br /&gt;
.so under Windows when building with Cygwin&lt;br /&gt;
.bundle under Mac OS X&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''C File'''&lt;br /&gt;
C codes to be invoked from Ruby&lt;br /&gt;
&lt;br /&gt;
An example Hello.c is shown below&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#include &amp;lt;ruby.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
// These C functions will be associated with&lt;br /&gt;
// methods of a Ruby class on the next page.&lt;br /&gt;
static VALUE hello(VALUE self, VALUE arg) {&lt;br /&gt;
 char* name = RSTRING(arg)-&amp;gt;ptr;&lt;br /&gt;
 printf(&amp;quot;Hello %s!\n&amp;quot;, name);&lt;br /&gt;
 return Qnil;&lt;br /&gt;
}&lt;br /&gt;
static VALUE goodbye(VALUE class) {&lt;br /&gt;
 printf(&amp;quot;Later dude!\n&amp;quot;);&lt;br /&gt;
 return Qnil;&lt;br /&gt;
}&lt;br /&gt;
// This is called when the Ruby interpreter loads this C extension.&lt;br /&gt;
// The part after &amp;quot;Init_&amp;quot; is the name of the C extension specified&lt;br /&gt;
// in extconf.rb, not the name of the C source file.&lt;br /&gt;
void Init_hello() {&lt;br /&gt;
 // Create a Ruby module.&lt;br /&gt;
 VALUE myModule = rb_define_module(&amp;quot;MyModule&amp;quot;);&lt;br /&gt;
 // Create a Ruby class in this module.&lt;br /&gt;
 // rb_cObject is defined in ruby.h&lt;br /&gt;
 VALUE myClass =&lt;br /&gt;
 rb_define_class_under(myModule, &amp;quot;MyClass&amp;quot;, rb_cObject);&lt;br /&gt;
 // Add an instance method to the Ruby class.&lt;br /&gt;
 int arg_count = 1;&lt;br /&gt;
 rb_define_method(myClass, &amp;quot;hello&amp;quot;, hello, arg_count);&lt;br /&gt;
 // Add a class method to the Ruby class.&lt;br /&gt;
 arg_count = 0;&lt;br /&gt;
 rb_define_module_function(myClass, &amp;quot;goodbye&amp;quot;, goodbye, arg_count);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*'''Ruby File'''&lt;br /&gt;
Ruby code that invokes C code&lt;br /&gt;
&lt;br /&gt;
*'''extending ruby from C'''&lt;br /&gt;
=== RubyInline ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== SWIG ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Ruby JAVA extensions''' ==&lt;/div&gt;</summary>
		<author><name>Qjia2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1h_jg&amp;diff=82935</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1h jg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1h_jg&amp;diff=82935"/>
		<updated>2014-02-04T21:23:47Z</updated>

		<summary type="html">&lt;p&gt;Qjia2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== '''Ruby libraries to load objects of other languages at run time''' ==&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby] is a dynamic, reflective, object-oriented, general-purpose programming language. It is easy to extend Ruby with new features by writing code in Ruby. But every now and then extending ruby with low-level languages, such as[http://en.wikipedia.org/wiki/C_(programming_language) C]/[http://en.wikipedia.org/wiki/C%2B%2B C++]/[http://en.wikipedia.org/wiki/Java_(programming_language) Java] is also necessary.&lt;br /&gt;
&lt;br /&gt;
Currently, various kinds of languages codes could be invoked from within ruby. The extension for C/C++ and Java are focused here.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== '''Ruby C/C++ extensions&amp;lt;ref&amp;gt;http://java.ociweb.com/mark/NFJS/RubyCExtensions.pdf&amp;lt;/ref&amp;gt;''' ==&lt;br /&gt;
By extending Ruby with C. The C libraries could be used directly in Ruby applications.&lt;br /&gt;
Ruby could call C codes in three ways: interpreter API, RubyInline, SWIG.&lt;br /&gt;
=== interpreter API ===&lt;br /&gt;
Ruby interpreter is implemented in C, its API can be used and no special API added for interacting with C like Java’s JNI is needed.&lt;br /&gt;
*'''mkmf (make makefile) Ruby Module'''&lt;br /&gt;
For this usage, platform-specific Makefiles for compiling C extensions to Ruby is needed to be generated firstly.&lt;br /&gt;
&lt;br /&gt;
A simple sample is like below:&lt;br /&gt;
&lt;br /&gt;
create a file containing the following,&lt;br /&gt;
named extconf.rb by convention&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'mkmf'&lt;br /&gt;
extension_name = 'name'&lt;br /&gt;
dir_config(extension_name)&lt;br /&gt;
create_makefile(extension_name)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
And use by running&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ruby extconf.rb&lt;br /&gt;
make&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then generates&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
.so under UNIX/Linux&lt;br /&gt;
.so under Windows when building with Cygwin&lt;br /&gt;
.bundle under Mac OS X&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== RubyInline ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== SWIG ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Ruby JAVA extensions''' ==&lt;/div&gt;</summary>
		<author><name>Qjia2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1h_jg&amp;diff=82934</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1h jg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1h_jg&amp;diff=82934"/>
		<updated>2014-02-04T21:21:31Z</updated>

		<summary type="html">&lt;p&gt;Qjia2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== '''Ruby libraries to load objects of other languages at run time''' ==&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby] is a dynamic, reflective, object-oriented, general-purpose programming language. It is easy to extend Ruby with new features by writing code in Ruby. But every now and then extending ruby with low-level languages, such as[http://en.wikipedia.org/wiki/C_(programming_language) C]/[http://en.wikipedia.org/wiki/C%2B%2B C++]/[http://en.wikipedia.org/wiki/Java_(programming_language) Java] is also necessary.&lt;br /&gt;
&lt;br /&gt;
Currently, various kinds of languages codes could be invoked from within ruby. The extension for C/C++ and Java are focused here.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== '''Ruby C/C++ extensions&amp;lt;ref&amp;gt;http://java.ociweb.com/mark/NFJS/RubyCExtensions.pdf&amp;lt;/ref&amp;gt;''' ==&lt;br /&gt;
By extending Ruby with C. The C libraries could be used directly in Ruby applications.&lt;br /&gt;
Ruby could call C codes in three ways: interpreter API, RubyInline, SWIG.&lt;br /&gt;
=== interpreter API ===&lt;br /&gt;
Ruby interpreter is implemented in C, its API can be used and no special API added for interacting with C like Java’s JNI is needed.&lt;br /&gt;
*'''mkmf (make makefile) Ruby Module'''&lt;br /&gt;
For this usage, platform-specific Makefiles for compiling C extensions to Ruby is needed to be generated firstly.&lt;br /&gt;
A simple sample is like below:&lt;br /&gt;
create a file containing the following,&lt;br /&gt;
named extconf.rb by convention&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'mkmf'&lt;br /&gt;
extension_name = 'name'&lt;br /&gt;
dir_config(extension_name)&lt;br /&gt;
create_makefile(extension_name)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
And use by running&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ruby extconf.rb&lt;br /&gt;
make&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then generates&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
.so under UNIX/Linux&lt;br /&gt;
.so under Windows when building with Cygwin&lt;br /&gt;
.bundle under Mac OS X&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== RubyInline ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== SWIG ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Ruby JAVA extensions''' ==&lt;/div&gt;</summary>
		<author><name>Qjia2</name></author>
	</entry>
</feed>